"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:
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?