1 # U-Boot with the datachk patchset requires image sizes, offsets,
2 # and checksums to be provided in the U-Boot environment.
3 # This script is based on the dualboot version for devices that come with 2 OS partitions.
4 # For Senao boards with a "failsafe" partition image, the process is almost the same.
5 # Instead of booting a secondary instalation on checksum failure,
6 # the failsafe image is booted instead.
7 # These boards also use the OKLI lzma kernel loader and mtd-concat
8 # So the kernel check is for the loader, the rootfs check is for kernel + rootfs
10 platform_do_upgrade_failsafe_datachk
() {
11 local setenv_script
="/tmp/fw_env_upgrade"
13 local flash_base
=0x9f000000
15 local kernel_mtd
=$
(find_mtd_index
${KERNEL_PART:-kernel})
16 local rootfs_mtd
=$
(find_mtd_index
${ROOTFS_PART:-rootfs})
18 local kernel_offset
=$
(cat /sys
/class
/mtd
/mtd
${kernel_mtd}/offset
)
19 local rootfs_offset
=$
(cat /sys
/class
/mtd
/mtd
${rootfs_mtd}/offset
)
21 if [ -n "$IMAGE_LIST" ]; then
22 KERNEL_FILE
=$
($IMAGE_LIST |
grep $KERNEL_FILE)
23 ROOTFS_FILE
=$
($IMAGE_LIST |
grep $ROOTFS_FILE)
26 local kernel_size
=$
($IMAGE_CMD $KERNEL_FILE |
wc -c)
27 local rootfs_size
=$
($IMAGE_CMD $ROOTFS_FILE |
wc -c)
29 # rootfs without JFFS2
30 local rootfs_blocks
=$
((rootfs_size
/ 4096))
31 rootfs_size
=$
((rootfs_blocks
* 4096))
33 local kernel_md5
=$
($IMAGE_CMD $KERNEL_FILE |
md5sum | cut
-d ' ' -f1)
34 local rootfs_md5
=$
($IMAGE_CMD $ROOTFS_FILE |
dd bs
=4k count
=$rootfs_blocks iflag
=fullblock |
md5sum | cut
-d ' ' -f1)
36 # prepare new u-boot-env vars
37 printf "vmlinux_start_addr 0x%08x\n" $
((flash_base
+ kernel_offset
)) >> $setenv_script
38 printf "vmlinux_size 0x%08x\n" ${kernel_size} >> $setenv_script
39 printf "vmlinux_checksum %s\n" ${kernel_md5} >> $setenv_script
41 printf "rootfs_start_addr 0x%08x\n" $
((flash_base
+ rootfs_offset
)) >> $setenv_script
42 printf "rootfs_size 0x%08x\n" ${rootfs_size} >> $setenv_script
43 printf "rootfs_checksum %s\n" ${rootfs_md5} >> $setenv_script
47 fw_setenv
-s $setenv_script ||
{
48 echo 'failed to update U-Boot environment'
55 echo 3 > /proc
/sys
/vm
/drop_caches
56 $IMAGE_CMD $KERNEL_FILE | mtd
$MTD_ARGS write - ${KERNEL_PART:-kernel}
59 if [ -n "$UPGRADE_BACKUP" ]; then
60 $IMAGE_CMD $ROOTFS_FILE | mtd
$MTD_ARGS $MTD_CONFIG_ARGS -j $UPGRADE_BACKUP write - ${ROOTFS_PART:-rootfs}
62 $IMAGE_CMD $ROOTFS_FILE | mtd
$MTD_ARGS write - ${ROOTFS_PART:-rootfs}