ath79: allow skipping hash for Senao sysupgrade
[openwrt/staging/dedeckeh.git] / target / linux / ath79 / generic / base-files / lib / upgrade / failsafe_datachk.sh
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
9
10 platform_do_upgrade_failsafe_datachk() {
11 local flash_base=0x9f000000
12
13 local kernel_mtd=$(find_mtd_index ${KERNEL_PART:-kernel})
14 local rootfs_mtd=$(find_mtd_index ${ROOTFS_PART:-rootfs})
15
16 local kernel_offset=$(cat /sys/class/mtd/mtd${kernel_mtd}/offset)
17 local rootfs_offset=$(cat /sys/class/mtd/mtd${rootfs_mtd}/offset)
18
19 if [ -n "$IMAGE_LIST" ]; then
20 KERNEL_FILE=$($IMAGE_LIST | grep $KERNEL_FILE)
21 ROOTFS_FILE=$($IMAGE_LIST | grep $ROOTFS_FILE)
22 fi
23
24 local kernel_size=$($IMAGE_CMD $KERNEL_FILE | wc -c)
25 local rootfs_size=$($IMAGE_CMD $ROOTFS_FILE | wc -c)
26
27 # rootfs without JFFS2
28 local rootfs_blocks=$((rootfs_size / 4096))
29 rootfs_size=$((rootfs_blocks * 4096))
30
31 local kernel_md5=$($IMAGE_CMD $KERNEL_FILE | md5sum | cut -d ' ' -f1)
32 local rootfs_md5=$($IMAGE_CMD $ROOTFS_FILE | dd bs=4k count=$rootfs_blocks iflag=fullblock | md5sum | cut -d ' ' -f1)
33
34 # prepare new u-boot-env vars
35 printf "vmlinux_start_addr 0x%08x\n" $((flash_base + kernel_offset)) >> $ENV_SCRIPT
36 printf "vmlinux_size 0x%08x\n" ${kernel_size} >> $ENV_SCRIPT
37 printf "vmlinux_checksum %s\n" ${kernel_md5} >> $ENV_SCRIPT
38
39 printf "rootfs_start_addr 0x%08x\n" $((flash_base + rootfs_offset)) >> $ENV_SCRIPT
40 printf "rootfs_size 0x%08x\n" ${rootfs_size} >> $ENV_SCRIPT
41 printf "rootfs_checksum %s\n" ${rootfs_md5} >> $ENV_SCRIPT
42
43 # store u-boot-env
44 mkdir -p /var/lock
45 [ -n "$SKIP_HASH" ] || fw_setenv -s $ENV_SCRIPT || {
46 echo 'failed to update U-Boot environment'
47 exit 1
48 }
49
50 # sysupgrade
51 sleep 2 && sync && echo 3 > /proc/sys/vm/drop_caches
52
53 $IMAGE_CMD $KERNEL_FILE | mtd $MTD_ARGS write - ${KERNEL_PART:-kernel}
54
55 sleep 2 && sync && echo 3 > /proc/sys/vm/drop_caches
56
57 if [ -n "$UPGRADE_BACKUP" ]; then
58 $IMAGE_CMD $ROOTFS_FILE | mtd $MTD_ARGS $MTD_CONFIG_ARGS -j $UPGRADE_BACKUP write - ${ROOTFS_PART:-rootfs}
59 else
60 $IMAGE_CMD $ROOTFS_FILE | mtd $MTD_ARGS write - ${ROOTFS_PART:-rootfs}
61 fi
62
63 sync
64 }