Initial commit
This commit is contained in:
64
target/linux/ramips/mt7621/base-files/lib/upgrade/iodata.sh
Normal file
64
target/linux/ramips/mt7621/base-files/lib/upgrade/iodata.sh
Normal file
@@ -0,0 +1,64 @@
|
||||
#
|
||||
# Copyright (C) 2019 OpenWrt.org
|
||||
#
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
iodata_mstc_prepare_fail() {
|
||||
echo "failed to check and prepare the environment, rebooting..."
|
||||
umount -a
|
||||
reboot -f
|
||||
}
|
||||
|
||||
# I-O DATA devices manufactured by MSTC (MitraStar Technology Corp.)
|
||||
# have two important flags:
|
||||
# - bootnum: switch between two os images
|
||||
# use 1st image in OpenWrt
|
||||
# - debugflag: enable/disable debug
|
||||
# users can interrupt Z-Loader for recovering the device if enabled
|
||||
#
|
||||
# parameters:
|
||||
# - $1: the offset of "debugflag"
|
||||
iodata_mstc_upgrade_prepare() {
|
||||
local persist_mtd="$(find_mtd_part persist)"
|
||||
local factory_mtd="$(find_mtd_part factory)"
|
||||
local dflag_offset="$1"
|
||||
|
||||
if [ -z "$dflag_offset" ]; then
|
||||
echo 'no debugflag offset provided'
|
||||
iodata_mstc_prepare_fail
|
||||
fi
|
||||
|
||||
if [ -z "$persist_mtd" ] || [ -z "$factory_mtd" ]; then
|
||||
echo 'cannot find mtd partition(s), "factory" or "persist"'
|
||||
iodata_mstc_prepare_fail
|
||||
fi
|
||||
|
||||
local bootnum=$(hexdump -s 4 -n 1 -e '"%x"' ${persist_mtd})
|
||||
local debugflag=$(hexdump -s $((dflag_offset)) -n 1 -e '"%x"' ${factory_mtd})
|
||||
|
||||
if [ "$bootnum" != "1" ] && [ "$bootnum" != "2" ]; then
|
||||
echo "failed to get bootnum, please check the value at 0x4 in ${persist_mtd}"
|
||||
iodata_mstc_prepare_fail
|
||||
fi
|
||||
if [ "$debugflag" != "0" ] && [ "$debugflag" != "1" ]; then
|
||||
echo "failed to get debugflag, please check the value at ${dflag_offset} in ${factory_mtd}"
|
||||
iodata_mstc_prepare_fail
|
||||
fi
|
||||
echo "current: bootnum => ${bootnum}, debugflag => ${debugflag}"
|
||||
|
||||
if [ "$bootnum" = "2" ]; then
|
||||
if ! (echo -ne "\x01" | dd bs=1 count=1 seek=4 conv=notrunc of=${persist_mtd} 2>/dev/null); then
|
||||
echo "failed to set bootnum"
|
||||
iodata_mstc_prepare_fail
|
||||
fi
|
||||
echo "### switch to 1st os-image on next boot ###"
|
||||
fi
|
||||
if [ "$debugflag" = "0" ]; then
|
||||
if ! (echo -ne "\x01" | dd bs=1 count=1 seek=$((dflag_offset)) conv=notrunc of=${factory_mtd} 2>/dev/null); then
|
||||
echo "failed to set debugflag"
|
||||
iodata_mstc_prepare_fail
|
||||
fi
|
||||
echo "### enable debug ###"
|
||||
fi
|
||||
}
|
||||
122
target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh
Executable file
122
target/linux/ramips/mt7621/base-files/lib/upgrade/platform.sh
Executable file
@@ -0,0 +1,122 @@
|
||||
#
|
||||
# Copyright (C) 2010 OpenWrt.org
|
||||
#
|
||||
|
||||
PART_NAME=firmware
|
||||
REQUIRE_IMAGE_METADATA=1
|
||||
|
||||
RAMFS_COPY_BIN='fw_printenv fw_setenv'
|
||||
RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock'
|
||||
|
||||
platform_check_image() {
|
||||
return 0
|
||||
}
|
||||
|
||||
platform_do_upgrade() {
|
||||
local board=$(board_name)
|
||||
|
||||
case "$board" in
|
||||
alfa-network,quad-e4g)
|
||||
[ "$(fw_printenv -n dual_image 2>/dev/null)" = "1" ] &&\
|
||||
[ -n "$(find_mtd_part backup)" ] && {
|
||||
PART_NAME=backup
|
||||
if [ "$(fw_printenv -n bootactive 2>/dev/null)" = "1" ]; then
|
||||
fw_setenv bootactive 2 || exit 1
|
||||
else
|
||||
fw_setenv bootactive 1 || exit 1
|
||||
fi
|
||||
}
|
||||
;;
|
||||
ampedwireless,ally-00x19k|\
|
||||
ampedwireless,ally-r1900k)
|
||||
if [ "$(fw_printenv --lock / -n bootImage 2>/dev/null)" != "0" ]; then
|
||||
fw_setenv --lock / bootImage 0 || exit 1
|
||||
fi
|
||||
;;
|
||||
mikrotik,routerboard-750gr3|\
|
||||
mikrotik,routerboard-760igs|\
|
||||
mikrotik,routerboard-m11g|\
|
||||
mikrotik,routerboard-m33g)
|
||||
[ "$(rootfs_type)" = "tmpfs" ] && mtd erase firmware
|
||||
;;
|
||||
asus,rt-ac65p|\
|
||||
asus,rt-ac85p)
|
||||
echo "Backing up firmware"
|
||||
dd if=/dev/mtd4 bs=1024 count=4096 > /tmp/backup_firmware.bin
|
||||
dd if=/dev/mtd5 bs=1024 count=52224 >> /tmp/backup_firmware.bin
|
||||
mtd -e firmware2 write /tmp/backup_firmware.bin firmware2
|
||||
;;
|
||||
esac
|
||||
|
||||
case "$board" in
|
||||
ampedwireless,ally-00x19k|\
|
||||
ampedwireless,ally-r1900k|\
|
||||
asus,rt-ac65p|\
|
||||
asus,rt-ac85p|\
|
||||
dlink,dir-1960-a1|\
|
||||
dlink,dir-2640-a1|\
|
||||
dlink,dir-2660-a1|\
|
||||
dlink,dir-853-a3|\
|
||||
hiwifi,hc5962|\
|
||||
jcg,q20|\
|
||||
linksys,e5600|\
|
||||
linksys,ea7300-v1|\
|
||||
linksys,ea7300-v2|\
|
||||
linksys,ea7500-v2|\
|
||||
linksys,ea8100-v1|\
|
||||
linksys,ea8100-v2|\
|
||||
netgear,r6220|\
|
||||
netgear,r6260|\
|
||||
netgear,r6350|\
|
||||
netgear,r6700-v2|\
|
||||
netgear,r6800|\
|
||||
netgear,r6850|\
|
||||
netgear,r6900-v2|\
|
||||
netgear,r7200|\
|
||||
netgear,r7450|\
|
||||
netgear,wac104|\
|
||||
netgear,wac124|\
|
||||
netis,wf2881|\
|
||||
sercomm,na502|\
|
||||
xiaomi,mi-router-3g|\
|
||||
xiaomi,mi-router-3-pro|\
|
||||
xiaomi,mi-router-4|\
|
||||
xiaomi,mi-router-ac2100|\
|
||||
xiaomi,redmi-router-ac2100)
|
||||
nand_do_upgrade "$1"
|
||||
;;
|
||||
iodata,wn-ax1167gr2|\
|
||||
iodata,wn-ax2033gr|\
|
||||
iodata,wn-dx1167r|\
|
||||
iodata,wn-dx2033gr)
|
||||
iodata_mstc_upgrade_prepare "0xfe75"
|
||||
nand_do_upgrade "$1"
|
||||
;;
|
||||
iodata,wn-dx1200gr)
|
||||
iodata_mstc_upgrade_prepare "0x1fe75"
|
||||
nand_do_upgrade "$1"
|
||||
;;
|
||||
ubnt,edgerouter-x|\
|
||||
ubnt,edgerouter-x-sfp)
|
||||
platform_upgrade_ubnt_erx "$1"
|
||||
;;
|
||||
zyxel,nr7101)
|
||||
fw_setenv CheckBypass 0
|
||||
fw_setenv Image1Stable 0
|
||||
CI_KERNPART="Kernel"
|
||||
nand_do_upgrade "$1"
|
||||
;;
|
||||
zyxel,wap6805)
|
||||
local kernel2_mtd="$(find_mtd_part Kernel2)"
|
||||
[ "$(hexdump -n 4 -e '"%x"' $kernel2_mtd)" = "56190527" ] &&\
|
||||
[ "$(hexdump -n 4 -s 104 -e '"%x"' $kernel2_mtd)" != "0" ] &&\
|
||||
dd bs=4 count=1 seek=26 conv=notrunc if=/dev/zero of=$kernel2_mtd 2>/dev/null &&\
|
||||
echo "Kernel2 sequence number was reset to 0"
|
||||
CI_KERNPART="Kernel"
|
||||
nand_do_upgrade "$1"
|
||||
;;
|
||||
*)
|
||||
default_do_upgrade "$1"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
78
target/linux/ramips/mt7621/base-files/lib/upgrade/ubnt.sh
Normal file
78
target/linux/ramips/mt7621/base-files/lib/upgrade/ubnt.sh
Normal file
@@ -0,0 +1,78 @@
|
||||
#
|
||||
# Copyright (C) 2015 OpenWrt.org
|
||||
#
|
||||
|
||||
. /lib/functions.sh
|
||||
#Note: this code also uses some functions from nand.sh, but it is expected to be run by nand.sh, so we are not
|
||||
#sourcing it explicitly here
|
||||
|
||||
UBNT_ERX_KERNEL_INDEX_OFFSET=160
|
||||
|
||||
ubnt_get_target_kernel() {
|
||||
local factory_mtd=$1
|
||||
local current_kernel_index=$(hexdump -s $UBNT_ERX_KERNEL_INDEX_OFFSET -n 1 -e '/1 "%X "' ${factory_mtd})
|
||||
|
||||
if [ $current_kernel_index == "0" ]; then
|
||||
echo 'kernel2'
|
||||
elif [ $current_kernel_index == "1" ]; then
|
||||
echo 'kernel1'
|
||||
fi
|
||||
}
|
||||
|
||||
ubnt_update_target_kernel() {
|
||||
local factory_mtd=$1
|
||||
local kernel_part=$2
|
||||
|
||||
local new_kernel_index
|
||||
if [ $kernel_part == "kernel1" ]; then
|
||||
new_kernel_index="\x00"
|
||||
elif [ $kernel_part == "kernel2" ]; then
|
||||
new_kernel_index="\x01"
|
||||
else
|
||||
echo 'Unknown kernel image index' >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
if ! (echo -e $new_kernel_index | dd of=${factory_mtd} bs=1 count=1 seek=$UBNT_ERX_KERNEL_INDEX_OFFSET); then
|
||||
echo 'Failed to update kernel bootup index' >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
platform_upgrade_ubnt_erx() {
|
||||
local factory_mtd=$(find_mtd_part factory)
|
||||
if [ -z "$factory_mtd" ]; then
|
||||
echo "cannot find factory partition" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
local kernel_part="$(ubnt_get_target_kernel ${factory_mtd})"
|
||||
if [ -z "$kernel_part" ]; then
|
||||
echo "cannot find factory partition" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# This is a global defined in nand.sh, sets partition kernel will be flashed into
|
||||
CI_KERNPART=${kernel_part}
|
||||
|
||||
#Remove volume possibly left over from stock firmware
|
||||
local ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
||||
if [ -z "$ubidev" ]; then
|
||||
local mtdnum="$( find_mtd_index "$CI_UBIPART" )"
|
||||
if [ -z "$mtdnum" ]; then
|
||||
echo "cannot find ubi mtd partition $CI_UBIPART" >&2
|
||||
exit 1
|
||||
fi
|
||||
ubiattach -m "$mtdnum"
|
||||
sync
|
||||
ubidev="$( nand_find_ubi "$CI_UBIPART" )"
|
||||
fi
|
||||
if [ -n "$ubidev" ]; then
|
||||
local troot_ubivol="$( nand_find_volume $ubidev troot )"
|
||||
[ -n "$troot_ubivol" ] && ubirmvol /dev/$ubidev -N troot || true
|
||||
fi
|
||||
|
||||
ubnt_update_target_kernel ${factory_mtd} ${kernel_part} || exit 1
|
||||
|
||||
nand_do_upgrade "$1"
|
||||
}
|
||||
Reference in New Issue
Block a user