Updating the Excito B3’s U-Boot

I currently run an Excito B3 device as my main router. Originally shipped with Debian installed, I got Arch Linux installed on it last year. I then decided to keep the original U-Boot despite its problem with L2 cache preventing it from booting any kernel newer than the 3.1 branch. Since then, the community did an incredible work, integrating the B3’s board first into ArchARM’s custom kirkwood kernel and then even in the mainline, and porting the board to the newest U-Boot.

Before anything, please note: the following may brick your B3 if not done properly and I discourage you to go on if you don’t understand how to unbrick your device using the serial (which means you may need a TTL cable and solder it to the mainboard).

First, you need to compile the new U-Boot. As it will run on the Bubba which is ARM-based, and that your own computer is probably not an ARM, you need to install the right cross-compilation toolchain. If you run Arch,

# pacman -S arm-none-eabi-{gcc,binutils}

If not, you will need to find the right package for you using your distribution’s package manager, compile it from source or find a pre-compiled one…

Then, get the marvellous code for the community-maintained U-Boot.

$ git clone https://github.com/Excito/community-b3-uboot.git

Before compiling your bootloader, remember to declare the prefix of your cross-compilation toolchain, then configure and build.

$ cd community-b3-uboot
$ export CROSS_COMPILE="arm-none-eabi-"
$ make distclean
$ make bubba3_config
$ make u-boot.kwb

If everything goes fine, you end up with a u-boot.kwb file, which is your bootloader plus some kirkwood specific code to allow booting from SPI flash. The next step is to upload this file to your B3. (Tip: Check the integrity of the transferred file, better safe than sorry).

Now log as root on the B3. You need the mtd-utils tools to work on the flash. You can get them using apt-get (or pacman if you have Arch on the B3).

The bootloader must be installed in the first partition of the flash, /dev/mtd0. The procedure is to first erase the whole partition, then write the bootloader image. Don’t forget to erase first, else it may lead to corrupted data being written. To first backup the data currently on the flash (a very good idea), you need to know the size of the partition.

# mtd_debug info /dev/mtd0
mtd.type = MTD_NORFLASH
mtd.flags = MTD_CAP_NORFLASH
mtd.size = 786432 (768K)
mtd.erasesize = 65536 (64K)
mtd.writesize = 1 
mtd.oobsize = 0 
regions = 0

Using that information, dump the whole partition.

# mtd_debug read /dev/mtd0 0 786432 mtd0.backup

Then, we’re good to go for real.

# flash_erase /dev/mtd0 0 0
# mtd_debug write /dev/mtd0 0 $(stat --printf '%s' "u-boot.kwb" ) "u-boot.kwb"

I suggest you check the data written somehow before rebooting. You may have a better idea than me, I just did

# strings /dev/mtd0 | less

and checked that it looked somewhat the same than

# strings u-boot.kwb | less

especially, for the version string

U-Boot 2013.01.01-ge588a77-dirty (Oct 09 2014 - 18:53:22)

Reboot. Good Luck!