OpenWrt Forum Archive

Topic: Once again: .bin and .trx

The content of this topic has been archived on 16 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

"How to use mtd to flash .bin files?"

I know, the "real" answer to this question is: Use .trx files, not .bin files. However, I like upgrading my OpenWRT box using the .bin files from downloads.openwrt.org/snapshots - I don't need or want to set up a build environment, I'm more than happy to benefit from others' work!

Various posts, e.g. 2007-05-19, give this command:

dd bs=32 skip=1 if=linksys.bin of=linksys.trx

Unfortunately, as that post says, this (sometimes) results in mtd saying "Bad trx header."

The Broadcom "Everything you need to know" Howto has a very helpful discussion of the .trx format, but no info on turning a .bin into a .trx file.

The FAQ (also in the forum, 2005-11-30) says "Converting the openwrt-wrt54g-squashfs.bin file back to a trx is just plain ignorant." Not only is that rude, I believe it's incorrect - mtd will not accept a .bin file, due to the header.

I got openwrt-wgt634u-2.6-squashfs.bin today, and used tftp to flash it (works great - hooray!), but it would have been much, much simpler to have used mtd.  Using the info from the Howto, I looked for the .trx header, so that I could use dd to strip this down to a .bin file:

$ hexdump -C openwrt-wgt634u-2.6-squashfs.bin | grep HDR0
00020000  48 44 52 30 00 10 1d 00  99 e3 71 15 00 00 01 00  |HDR0.....ãq.....|

Can that be right?  The .bin header to be stripped is 0x20000 bytes (128kB), and not 32 bytes?  Suddenly, I'm not so confident that I'll have a working router after flashing...

See also "Bad trx header.," which includes this tidbit of information:

thepeople wrote:

The ability to flash .bin images have been removed from Kamikaze, use the .trx to flash from the command line.

Does that mean that mtd used to know how to skip past the .bin header, and then write the .trx to flash? Was that limited to 32-byte headers, or could it scan arbitrarily until it saw a .trx header?  That seems like a simple bit of programming, and incredibly useful... Anyone care to fill me in on the reason for removing that ability?

But, is there not a .trx in the snapshot too?

Mind though, it dated July 11, whereas the 7.07 is dated July 26, so I doubt the snapshots are up to date...

cybermaus wrote:

But, is there not a .trx in the snapshot too?

Good point! Yes, there is... for the brcm-2.4 build, but not for the wgt634u build.

(I was going to be really, really embarrassed if they'd added .trx builds to that directory while I wasn't looking...)

Look, I know that I'm depending on the kindness of [s]strangers[/s]* others to create these files.  I would have no objections to bin-only builds, *IF* mtd were (still) able to use them. I guess that's my main point - if it's just a matter of stripping off everything leading up to the .trx header, why can't mtd do that?

*Spoiler: The movie's big finish

thepeople wrote:

there is a .trx in the brcm-47xx directory http://downloads.openwrt.org/snapshots/ … uashfs.trx

True. I could trust that, or I could hold out for a "real" wgt634u build.  I really didn't want to do a lot of test-flashes to my router.

Meanwhile, since it was you I was quoting before... Is it true that mtd used to know how to skip past the .bin header, and then write the .trx to flash? Was that limited to 32-byte headers, or could it scan arbitrarily until it saw a .trx header?  That seems like a simple bit of programming, and incredibly useful... Care to fill me in on the reason for removing that ability?

Well, now that you've overhyped everything and built it into a huge controversy -

The mtd util will blindly write whatever file you give it directly to flash, no questions asked. This is because not all platforms use the trx format, and it's also useful to be able to use the utility for other sections of the flash. A trx file starts with the characters "HDR0", this usually starts at the 32 byte mark, but it depends on platform - you can't insist that any bin file can be converted into a trx by stripping off 32 bytes.

The discussion might have continued from here.