d0ed258890f921f53ed1263f5a304f3ca530d593
[openwrt/staging/jow.git] / target / linux / qualcommax / base-files / lib / upgrade / buffalo.sh
1 . /lib/functions.sh
2
3 # Prepare UBI devices for OpenWrt installation
4 # - rootfs (mtd22)
5 # - remove "ubi_rootfs" volume (rootfs on stock)
6 # - remove "fw_hash" volume (firmware hash)
7 # - user_property (mtd24)
8 # - remove "user_property_ubi" volume (user configuration)
9 # - remove "extra_property" volume (gzipped syslog)
10 buffalo_upgrade_prepare() {
11 local ubi_rootdev ubi_propdev
12
13 if ! ubi_rootdev="$(nand_attach_ubi rootfs)" || \
14 ! ubi_propdev="$(nand_attach_ubi user_property)"; then
15 echo "failed to attach UBI volume \"rootfs\" or \"user_property\", rebooting..."
16 reboot -f
17 fi
18
19 ubirmvol /dev/$ubi_rootdev -N ubi_rootfs &> /dev/null || true
20 ubirmvol /dev/$ubi_rootdev -N fw_hash &> /dev/null || true
21
22 ubirmvol /dev/$ubi_propdev -N user_property_ubi &> /dev/null || true
23 ubirmvol /dev/$ubi_propdev -N extra_property &> /dev/null || true
24 }
25
26 # Re-create small dummy ubi_rootfs volume and update
27 # fw_hash volume to pass the checking by U-Boot
28 # - rootfs (mtd22)
29 # - re-create "ubi_rootfs" volume
30 # - re-create and update "fw_hash" volume
31 # - rootfs_recover (mtd23)
32 # - update "fw_hash" volume
33 buffalo_upgrade_optvol() {
34 local ubi_rootdev ubi_rcvrdev
35 local hashvol_root hashvol_rcvr
36
37 if ! ubi_rootdev="$(nand_attach_ubi rootfs)" || \
38 ! ubi_rcvrdev="$(nand_attach_ubi rootfs_recover)"; then
39 echo "failed to attach UBI volume \"rootfs\" or \"rootfs_recover\", rebooting..."
40 reboot -f
41 fi
42
43 ubimkvol /dev/$ubi_rootdev -N ubi_rootfs -S 1
44 ubimkvol /dev/$ubi_rootdev -N fw_hash -S 1 -t static
45
46 if ! hashvol_root="$(nand_find_volume $ubi_rootdev fw_hash)" || \
47 ! hashvol_rcvr="$(nand_find_volume $ubi_rcvrdev fw_hash)"; then
48 echo "\"fw_hash\" volume in \"rootfs\" or \"rootfs_recover\" not found, rebooting..."
49 reboot -f
50 fi
51
52 echo -n "00000000000000000000000000000000" > /tmp/dummyhash.txt
53 ubiupdatevol /dev/$hashvol_root /tmp/dummyhash.txt
54 ubiupdatevol /dev/$hashvol_rcvr /tmp/dummyhash.txt
55 }