I have decided to format the NAND flash like this:
/dev/mtd0 : 0x00000000-0x00300000 : 3 MB : "kernel1"And made device soft link like:
/dev/mtd1 : 0x00300000-0x01300000 : 16 MB : "cramfs1"
/dev/mtdblock2 : 0x01300000-0x01700000 : 4 MB : "jffs2"
/dev/mtdblock3 : 0x01700000-0x01800000 : 1 MB : "nvram"
/dev/mtd4 : 0x01800000-0x01b00000 : 3 MB : "kernel2"
/dev/mtd5 : 0x01b00000-0x02b00000 : 16 MB : "cramfs2"
/dev/mtd-kernel -> mtd0How does U-Boot does the boot process:
/dev/mtd-rfs -> mtd1
/dev/mtd-kernel-alt -> mtd4
/dev/mtd-rfs-alt -> mtd5
1. Read kernel from NAND to RAM
2. un-compress the kernel to RAM
3. execute kernel
Ex:-
bootcmd=nand read <TO> <FROM> <SIZE>; \
gunzip <FROM> <SIZE> <TO> <MAX SIZE>; \
bootoctlinux <NEW FROM> root=/dev/mtdblock1 ${mtdparts}
bootcmd=nand read 0x500000 0x00000 0x300000; \
gunzip 0x500000 0x300000 0x2800000 0xf00000; \
bootoctlinux 0x2800000 root=/dev/mtdblock1 ${mtdparts}
Solution:
1. get the current kernel information from U-Boot parameter
2. burnel kernel image in alternate locations (mtd0, mtd5)
3. update U-Boot parameter
Ideal U-Boot parameters:
bootcmd=run boot1firmware upgrade script:
altbootcmd=run boot2
boot1=namedfree __tmp_reserved_bootloader; \
nand read 500000 00000 300000; \
run boot11
boot2=namedfree __tmp_reserved_bootloader; \
nand read 500000 1800000 300000; \
run boot21
mtdparts=mtdparts=cavium-nand:3072k(kernel1),16384k(cramfs1), \
4096k(jffs2),1024k(nvram), \
3072k(kernel2),16384k(cramfs2),3072k()
boot11=gunzip 0x500000 300000 0x2800000 0xf00000; \
bootoctlinux 2800000 root=/dev/mtdblock1 ${mtdparts}
boot21=gunzip 0x500000 300000 0x2800000 0xf00000; \
bootoctlinux 2800000 root=/dev/mtdblock5 ${mtdparts}
#!/bin/sh
bootcmd=`bootenv -d bootcmd`
altcmd=`bootenv -d altbootcmd`
if [ "$bootcmd" == "run boot1" ];
then
kernelimage="/dev/mtd-kernel-alt"
rfsimage="/dev/mtd-rfs-alt"
else
kernelimage="/dev/mtd-kernel"
rfsimage="/dev/mtd-rfs"
fi
# Kernel in mtd-kernel
echo "Erasing the kernel image in $kernelimage"
echo -n "Flashing in the new kernel image. Please wait..."
# Root File System in mtd-rfs
echo "Erasing the root f/s image in $rfsimage"
echo -n "Flashing in the new root f/s image. Please wait..."
if [ "$bootcmd" == "run boot1" ];
then
echo "Setting new bootcmd as run boot2 and backup as run boot1"
bootenv -s bootver "$upgradeVersion"
bootenv -s bootcmd "run boot2"
bootenv -s altbootver "$existingVersion"
bootenv -s altbootcmd "run boot1"
else
echo "Setting new bootcmd as run boot1 and backup as run boot2"
bootenv -s bootver "$upgradeVersion"
bootenv -s bootcmd "run boot1"
bootenv -s altbootver "$existingVersion"
bootenv -s altbootcmd "run boot2"
fi
/bin/sync
/bin/sleep 2
# Reboot
exec /sbin/init -r
Reference: