1 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 Jeff Kletsky
6 glinet_using_boot_dev_switch
() {
7 if [ "$(fw_printenv -n boot_dev 2>/dev/null)" = "on" ] ; then
8 >&2 echo "NOTE: boot_dev=on; use switch to control boot partition"
15 glinet_set_next_boot_nand
() {
17 ! glinet_using_boot_dev_switch
&& \
18 fw_setenv bootcount
0 && \
19 >&2 echo "Next boot set for NAND"
22 glinet_set_next_boot_nor
() {
24 ! glinet_using_boot_dev_switch
&& \
25 fw_setenv bootcount
3 && \
26 >&2 echo "Next boot set for NOR"
29 glinet_nand_nor_do_upgrade
() {
30 set_next_boot_nand
() { glinet_set_next_boot_nand
; }
31 set_next_boot_nor
() { glinet_set_next_boot_nor
; }
32 nand_nor_do_upgrade
"$1"
35 nand_nor_do_upgrade
() {
36 local upgrade_file
="$1"
42 case "$(get_magic_long "$upgrade_file")" in
44 "27051956") # U-Boot Image Magic
46 for pn
in "nor_${PART_NAME}" "$PART_NAME" ; do # firmware
47 if [ "$(find_mtd_index "$pn")" ] ; then
53 if [ "$found" = "yes" ] ; then
54 >&2 echo "Running NOR upgrade"
55 default_do_upgrade
"$upgrade_file"
56 # At this time, default_do_upgrade() exits on error
57 type set_next_boot_nor
>/dev
/null
&& set_next_boot_nor
59 >&2 echo "ERROR: UPGRADE FAILED: Unable to locate '$PART_NAME' or 'nor_${PART_NAME}'"
64 *) # otherwise a file that nand_do_upgrade can process
66 for pn
in "nand_${CI_KERNPART}" "$CI_KERNPART" ; do # kernel
67 if [ "$(find_mtd_index "$pn")" ] ; then
72 for pn
in "nand_${CI_UBIPART}" "$CI_UBIPART" ; do # ubi
73 if [ "$(find_mtd_index "$pn")" ] ; then
78 for pn
in "nand_${CI_ROOTPART}" "$CI_ROOTPART" ; do #rootfs
79 if [ "$(find_mtd_index "$pn")" ] ; then
84 >&2 echo "Running NAND upgrade"
85 # TODO: change order when NAND upgrade offers return
86 type set_next_boot_nand
>/dev
/null
&& set_next_boot_nand
87 nand_do_upgrade
"$upgrade_file"