1 linksys_get_target_firmware
() {
2 local cur_boot_part mtd_ubi0
4 cur_boot_part
="$(/usr/sbin/fw_printenv -n boot_part)"
5 if [ -z "${cur_boot_part}" ]; then
6 mtd_ubi0
=$
(cat /sys
/class
/ubi
/ubi
0/mtd_num
)
7 case "$(grep -E "^mtd
${mtd_ubi0}:" /proc/mtd | cut -d '"' -f 2)" in
11 alt_kernel|alt_rootfs)
15 >&2 printf "Current boot_part='%s
' selected from ubi0/mtd_num='%s
'" \
16 "${cur_boot_part}" "${mtd_ubi0}"
19 # OEM U-Boot for EA6350v3, EA8300 and MR8300; bootcmd=
20 # if test $auto_recovery = no;
22 # elif test $boot_part = 1;
27 case "$cur_boot_part" in
50 linksys_is_factory_image() {
51 local board=$(board_name)
54 # check matching footer signature
55 tail -c 256 $1 | grep -q -i "\.LINKSYS\.........${board}"
58 platform_do_upgrade_linksys() {
59 local magic_long="$(get_magic_long "$1")"
61 local rm_oem_fw_vols="squashfs ubifs" # from OEM [alt_]rootfs UBI
65 local part_label="$(linksys_get_target_firmware)"
66 touch /var/lock/fw_printenv.lock
68 if [ -z "$part_label" ]; then
69 echo "cannot find target partition"
73 local target_mtd=$(find_mtd_part "$part_label")
75 [ "$magic_long" = "73797375" ] && {
76 CI_KERNPART="$part_label"
77 if [ "$part_label" = "kernel" ]; then
80 CI_UBIPART="alt_rootfs"
83 local mtdnum="$(find_mtd_index "$CI_UBIPART")"
84 if [ ! "$mtdnum" ]; then
85 echo "cannot find ubi mtd partition $CI_UBIPART"
89 local ubidev="$(nand_find_ubi "$CI_UBIPART")"
90 if [ ! "$ubidev" ]; then
91 ubiattach -m "$mtdnum"
93 ubidev="$(nand_find_ubi "$CI_UBIPART")"
96 if [ "$ubidev" ]; then
97 for vol in $rm_oem_fw_vols; do
98 ubirmvol "/dev/$ubidev" -N "$vol" 2>/dev/null
102 # complete std upgrade
103 nand_upgrade_tar "$1"
106 [ "$magic_long" = "27051956" ] && {
107 echo "writing \"$1\" image to \"$part_label\""
108 get_image "$1" | mtd write - "$part_label"
111 [ "$magic_long" = "d00dfeed" ] && {
112 if ! linksys_is_factory_image "$1"; then
113 echo "factory image doesn't match device
"
117 echo "writing
\"$1\" factory image to
\"$part_label\""
118 get_image "$1" | mtd -e "$part_label" write - "$part_label"