2 # Copyright (C) 2018 OpenWrt.org
7 # The mtd partition 'ubi' and 'rootfs_1' on NAND flash are os-image
8 # partitions. These partitions are called as "Bank1/Bank2" in U-Boot
9 # on WXR-2533DHP, and they are checked conditions when booting.
10 # Then, U-Boot checks kernel and rootfs volumes in ubi, but U-Boot
11 # needs "ubi_rootfs" as rootfs volume name. And, U-Boot checks the
12 # checksum at the end of rootfs (ubi_rootfs).
13 # When U-Boot writes os-image into the Bank, only kernel, rootfs
14 # (ubi_rootfs) and rootfs_data (ubi_rootfs_data) volumes are wrote
15 # into the Bank. (not full ubi image)
17 # == U-Boot Behaviors ==
18 # - Bank1/Bank2 images are good, images are different
19 # -> writes os-image to Bank1 from Bank2
20 # (this behavior is used to firmware upgrade in stock firmware)
21 # - Bank1 image is broken (or checksum error)
22 # -> writes os-image to Bank1 from Bank2
23 # - Bank2 image is broken (or checksum error)
24 # -> writes os-image to Bank2 from Bank1
25 # - Bank1/Bank2 images are broken (or checksum error)
28 buffalo_upgrade_prepare_ubi
() {
29 local ubidev
="$( nand_find_ubi ubi )"
30 local mtdnum2
="$( find_mtd_index rootfs_1 )"
32 if [ ! "$mtdnum2" ]; then
33 echo "cannot find second ubi mtd partition rootfs_1"
37 local ubidev2
="$( nand_find_ubi rootfs_1 )"
38 if [ ! "$ubidev2" ] && [ -n "$mtdnum2" ]; then
39 ubiattach
-m "$mtdnum2"
40 ubidev2
="$( nand_find_ubi rootfs_1 )"
43 ubirmvol
/dev
/$ubidev -N ubi_rootfs_data
&> /dev
/null || true
44 ubirmvol
/dev
/$ubidev2 -N kernel
&> /dev
/null || true