[maemo-developers] [maemo-developers] HOWTO almost brick your device and get tons of bad blocks in flash (and recover)

From: Frantisek Dufka dufkaf at seznam.cz
Date: Tue Aug 8 00:13:29 EEST 2006

this is not howto that should be followed but a (bit long) warning.

I tried to find a way of reflashing initfs partition from device itself. 
In theory it should be possible via mtd-tools if done correctly. I 
underestimated a bit how dangerous this stuff is so I went ahead. First 
I reflashed initfs via 'nandwrite /dev/mtd3 initfs.jffs' but the device 
did not boot so I reflashed with flasher and it worked again. Then I 
tried nandwrite flag -j which, according to some information on the net, 
should be used to flash jffs2 partition. It was wrong. Really wrong. It 
did not boot too so I reflashed initfs again with flasher and it worked 
again. After boot I noticed in dmesg output that flashing with nandwrite 
or something else I did before marked all flashed blocks bad - initfs 
image had 1.5MB so it means 1.5MB of bad blocks in initfs partition! And 
initfs partition is in normal situation 2MB long! Since I didn't know 
what exactly made those bad blocks and was a bit slow in thinking I 
actually repeated my steps again and managed to make 3MB of bad blocks 
in total :-)

Only then I searched linux-mtd list and found that
1. I should have used 'flash_eraseall' first before writing with 
nandwrite [1]
2. -j flag to nandwrite should not be used to flash jffs filesystems and 
will probably be removed [2]

Luckily Nokia flasher or bootloader (and also linux kernel) can recover 
from this situation. It simply skips bad blocks and enlarges initfs 
partition so next good blocks are used. This is really great solution, 
thank you Nokia people for making my device still booting even when 
trying so hard to kill it :-)

As a side effect this initfs partition enlargement also moves begining 
of root partition which makes the device unbootable (the root jffs2 
filesystem is missing the beginning). Luckily there is the boot menu and 
I have mmc card with root filesystem copy booting so I actually didn't 
notice anything at first :-)

Only later I have found that the partition sizes changed - see my 
request for help [3] for full details.

By searching mtd-linux mailing list further and examining kernel and 
mtd-utils source I found that there is no easy way to get my 'bad' 
blocks back. Both sources contain bad block checks and kernel prevents 
erasing bad blocks. I had to comment out these checks and in the end it 
worked! With custom kernel and flash_eraseall the result is that bad 
blocks are gone again :-) But my initfs partition still stays enlarged.

[    4.416931] 5 cmdlinepart partitions found on MTD device omap-nand
[    4.417053] Creating 5 MTD partitions on "omap-nand":
[    4.417175] 0x00000000-0x00020000 : "bootloader"
[    4.418853] 0x00020000-0x00080000 : "config"
[    4.420318] 0x00080000-0x00280000 : "kernel"
[    4.421813] 0x00280000-0x00780000 : "initfs"
[    4.423248] 0x00780000-0x08000000 : "root"

Filesystem           1k-blocks      Used Available Use% Mounted on
/dev/mtdblock3            5120      1924      3196  38% /mnt/initfs

Actually I like this layout. There is more space for modules and other 
uclibc stuff for further experiments. But still - is there some way of 
reverting back to 2MB big initfs? Maybe reflashing whole fiasco image at 

Anyway, it looks like I was really extremely lucky that after all things 
I did I still have my precious N770 working. I still didn't succeed in 
reflashing from the device but I hope it is just matter of using 
flash_eraseall and then writing with nandwrite. But it will take few 
days until I refill my bucket of courage and go ahead and try again :-)


1 http://lists.infradead.org/pipermail/linux-mtd/2005-March/012045.html
2 http://lists.infradead.org/pipermail/linux-mtd/2006-August/016256.html
3 http://lists.infradead.org/pipermail/linux-mtd/2006-August/016287.html

More information about the maemo-developers mailing list