OpenWrt Forum Archive

Topic: How to upgrade from RC2 to RC3 via mtd?

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

Greetings,

It looks like a trivial question, but after reading the threads and the README for RC3 I guess there is some inconsistency in the information.

For the record, I have a Linksys WRT54G with RC2 running fine.

I would like to upgrade to RC3 using mtd. 00_README in the section "Upgrading from a previous openwrt install" says:
To reflash from openwrt you will need a TRX file, generally the "openwrt-brcm-2.4-squashfs.trx" file.

When looking in the bin dir, I see the brcm file referenced above and also the one I need for my router, namely openwrt-wrt54g-squashfs.bin

Is there a way to use mtd to upgrade from RC2 to RC3 directly from OpenWRT (ie. not via tftp)? Should I use:

mtd -r write openwrt-wrt54g-squashfs.bin linux

?

Thanks in advance,
Wojtek

wsw70 wrote:

Greetings,

It looks like a trivial question, but after reading the threads and the README for RC3 I guess there is some inconsistency in the information.

For the record, I have a Linksys WRT54G with RC2 running fine.

I would like to upgrade to RC3 using mtd. 00_README in the section "Upgrading from a previous openwrt install" says:
To reflash from openwrt you will need a TRX file, generally the "openwrt-brcm-2.4-squashfs.trx" file.

When looking in the bin dir, I see the brcm file referenced above and also the one I need for my router, namely openwrt-wrt54g-squashfs.bin

Is there a way to use mtd to upgrade from RC2 to RC3 directly from OpenWRT (ie. not via tftp)? Should I use:

mtd -r write openwrt-wrt54g-squashfs.bin linux

?

Thanks in advance,
Wojtek

When upgrading from RC2 (squashfs) to RC3 you should use:

mtd -e linux -r write openwrt-wrt54g-squashfs.trx linux

Note I've added -e linux. Than it should work just fine.

(Last edited by olli_04 on 26 Sep 2005, 20:03)

Czeszcz Wojtek, hallo Olli and greetings all,

Quoting the same http://downloads.openwrt.org/whiterussian/00-README:

TRX extension:
      These are the firmware in raw format, suitable for writing directly
      to the flash or for vendors that don't require a BIN file.

    BIN extension:
      Same as above but with a vendor specific header.

In other words TRX is for writing directly using mtd and BIN is for uploading via tftp or a vendor web interface.

I'm almost sure that the different BIN files are identical except for the first 32 bit. But if you want to use a BIN file with mtd you have to remove the first 32 and produce a TRX file:

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

Thank you Olli and AEblefisk for your help.

I have just reflashed my router and .. it works smile

This is a very powerful forum.

Wojtek

The only difference between bin and trx files (or even between two bin files) is the device specific information in the bin files before the trx data starts. The trx files are run through a until which adds a bin header; the headers are generally about 32 bytes and contain things like the model name and firmware version number. This is extra information that once validated is never actually stored; only a few things like the web upgrade check for the bin header.

Although I've said most of this before, I'll repeat it since it's been awhile since the last time and I want to clear up a few myths:

(This is a somewhat abridged version, if you need more details of anything here just start a new thread and ask)

The flash is 4M (or 8M) of continuous space; no partition table, just data (the location of various items is pretty much just hardcoded into the applications that access the flash). When the device boots, it loads the first thing in flash -- no, not the firmware, another application called CFE (common flash environment, most people just call it "the bootloader"). The bootloader is responsible for initializing the hardware and validating the firmware; should the firmware fail (or if you have boot_wait set) it also provides a tftp server for uploading new firmware. The bootloader takes the first 256k of flash, and NVRAM data takes about the last 64k of flash; between the bootloader and NVRAM is essentially free space for the firmware to do whatever it wants.

Typically, right at the start of the firmware space (the 256k mark) is a trx file (the complete file, headers and all). The trx is the firmware and contains a kernel and a filesystem; after this is just wasted space.

Openwrt isn't "typical"; we're not about to waste 1M or more of space. So, in OpenWrt, almost immediately after the firmware ends, a jffs2 partition begins. This jffs2 partition is what allows us to store changes to the filesystem.

Reflashing the device only overwrites the firmware area with a trx file. It does not explicitly erase this area unless told to do so. What does this mean? Typically nothing, since nothing is outside of the trx, but this being OpenWrt, there's some jffs2 data there...

If this is the first time you've installed Openwrt, there's no jffs2 data. This isn't much of a problem since OpenWrt will just create a new jffs2.

If you're upgrading openwrt versions and the new firmware is roughly the same size as the last firmware, the jffs2 partition starts at the same place and none of the jffs2 data is overwritten. Or to put it another way, if you screw up the jffs2 partition, reflashing isn't going to help since it doesn't change the jffs2 partition in any way.

If you're upgrading and the new firmware is smaller, then there's more room for jffs2 and the jffs2 partition starts earlier, however since none of the jffs2 data has been erased, the partition is still perfectly usable and even adapts itself for the new partition size.

If you're upgrading and the new firmware is larger, then the trx file takes more space on the flash and overwrites what used to be jffs2 data. Now a large chunk of jffs2 data is missing, but since there's still some valid data, the partition may be mountable -- it'll just have some nasty corruption and missing files that prevent it from booting.

The solution has always been to boot into failsafe (failsafe doesn't use jffs2), and either examine and fix the jffs2 partition manually, or run firstboot to recreate it. This presents a bit of a problem since some devices aren't in convient locations to try to get into failsafe, and some users just outright don't read the manual to know about failsafe. So, starting with rc3 the instructions for upgrading include "mtd -e linux write ...." The "-e linux" erases the entire firmware area, clearing out any jffs2 data, allowing Openwrt to boot and recreate the jffs2 partition. This isn't a change in the software (It works the same as any other Openwrt release), it's just a change in the instructions so we don't have to answer as many questions about failed upgrades. Also, it only applies to users that already have jffs2 data; don't install an old release just so you can upgrade using the mtd command.

And now a quick word about the jffs2 firmwares (feel free to skip this section if it doesn't apply to you):

The jffs2 firmwares are firmware images that don't have a squashfs partition, the entire filesystem is jffs2. Since there isn't any squashfs partition, any changes you make to the filesystem can't be reverted or ignored; this means that failsafe really doesn't do much to recover from filesystem errors. If you screw up the filesystem reflash (I know what I said earlier, jffs2 is an exception). Let me explain - The first time it boots, the jffs2 data is within the firmware, a utility is run to modify the size of the trx on the flash and the jffs2 partition is moved outside of the firmware -- This is why the jffs2 firmwares are readonly at first and require an extra reboot.

The discussion might have continued from here.