RT-AC58U TRX image creation

Following are the steps to create ASUS TRX image from Openwrt ITB image.

When I was looking into ASUS source code for RT-AC58U found that there is a mkimage binary under asuswrt/release/src-qca-dakota/asustools folder , playing with it for while along with looking into binary image released by ASUS I found that TRX is just a header created on top of ITB image. I spent time to document the header which I am putting here. The command I used to create TRX image is (as mentioned in here)
mkimage -n "OpenWrt" -A arm -O linux -T kernel -C lzma -a 0x80208000 -e 0x80208000 -M 0x27051956 -d openwrt-18.06.2-ipq40xx-asus_rt-ac58u-initramfs-fit-uImage.itb openwrt-18.06.2-ipq40xx-asus_rt-ac58u-initramfs-fit-uImage.trx

Hope this information is useful for devs to create or update image creations tools. This format seems to be used across as ASUS router firmware

Header Documentation:
--------------------------------
u32 - magic - 0x27051956
u32 - unknown - Time 1
u32 - unknown - TIme 2 (along with Time 1 appers to be file creation time in nano seconds??)
u32 - Image length excluding this header
u32 - Kernel Load Addr
u32 - Kernel Entry Addr
u32 - crc32 of the image
u32 unknown (mostly flags)
u32 - (kernel + FS) version (Kernel Major << 24 + Kernel Minor << 16 + FS Major << 8 + FS Minor)
u8[12] - model String
u8[16] - padding or name string
-----------------------
Flags:

1) -T Image Type (flags << 8)
   aisimage
   filesystem
   firmware
   flat_dt
   kernel - 0x02
   kernel_noload
   kwbimage
   imximage
   multi
   omapimage
   pblimage
   ramdisk
   script
   standalone
   ublimage
2) -C Compression Type (flags << 0)
   none 0x00
   bzip2 - 0x02
   gzip - 0x01
   lzma - 0x03
   lzo - 0x04

3) -A CPU Type (flags << 16)
   alpha - 0x01
   arm - 0x02
   x86 - 0x03
   ia64 - 0x04
   m68k
   microblaze -x0E
   mips
   mips64 - 0x06
   nios2
   powerpc
   ppc
   s390 0x08
   sh
   sparc
   sparc64
   blackfin - 0x10
   avr32
   nds32
   or1k
   sandbox - 0x13
4) -O OS Type (flags << 24)
   linux - 0x05
   lynxos - 0x0D
   netbsd - 0x02
   ose - 0x16
   plan9 - x17
   rtems
   u-boot
   qnx
   vxworks
   integrity
   4_4bsd
   dell
   esix
   freebsd
   irix
   ncr
   openbsd
   psos
   sco
   solaris
   svr4

Does this mean that we can refresh the router to Openwrt directly from webcgi instead of hacking the serial port ? If so, can you please share the url where the source code you mentioned (asuswrt/release/src-qca-dakota/asustools) is available. Thank you

Yes, you can flash openwrt from Asus web UI, the source is from https://dlcdnets.asus.com/pub/ASUS/wireless/RT-AC58U/GPL_RT_AC58U_30043808457.zip

Following your instructions I have packed a trx firmware myself targeting the latest 18.06.4 branch. I have uploaded to google drive here

But we I tried to upload to router through the WebUI, the OEM firmware rejected my openwrt firmware informing

Firmware upgrade unsuccessful. This might result from incorrect image or error transmission, please check the model name RT-ACRH13 and version of firmware from support site and try again.

As far as I understand, RT-ACRH13 (my device) has exactly the same hardware with RT-AC58U, does this (RT-ACRH13 vs RT-AC58U) matter, or cause the failure ?

ARCH13 is US model number of AC58U and I also have ARCH13. did you use the mkimage command and parameters I mentioned above?

I have created trx from official 18.06.4 image for you try here

Yes I used the mkimage command and parameters you mentioned above.
Thank you for the help, I have tried your version but the OEM system rejected it as well with the same error message.
I have compared your version and my version, they have exactly identical file length (4 727 752 bytes), and the only difference happens within the first 16 bytes. Not very sure what caused the diff while unfortunately neither of them works ...
Your version

27 05 19 56 b7 cb f7 fe 5d 22 03 22 20 48 23 88

My version

27 05 19 56 be ed 28 fd 5d 21 b5 f5 20 48 23 88

I am sorry, I have no way to test now as I retired my AC58U, but it worked for me when I bought the unit and flashed to openwrt though web UI.

No problem thank you all the same