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