[PATCH] bcm4908: implement basic sysupgrade support
From: Rafał Miłecki It isn't UBI aware yet - that remains to be implemented. Signed-off-by: Rafał Miłecki --- target/linux/bcm4908/Makefile | 4 +- .../base-files/lib/upgrade/platform.sh| 114 ++ 2 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 target/linux/bcm4908/base-files/lib/upgrade/platform.sh diff --git a/target/linux/bcm4908/Makefile b/target/linux/bcm4908/Makefile index 5bee66fe2b..5f80c2f6ca 100644 --- a/target/linux/bcm4908/Makefile +++ b/target/linux/bcm4908/Makefile @@ -20,6 +20,8 @@ include $(INCLUDE_DIR)/target.mk KERNELNAME:=Image dtbs -DEFAULT_PACKAGES += kmod-usb-ohci kmod-usb2 kmod-usb3 +DEFAULT_PACKAGES += \ + bcm63xx-bootfs \ + kmod-usb-ohci kmod-usb2 kmod-usb3 $(eval $(call BuildTarget)) diff --git a/target/linux/bcm4908/base-files/lib/upgrade/platform.sh b/target/linux/bcm4908/base-files/lib/upgrade/platform.sh new file mode 100644 index 00..e285b9e013 --- /dev/null +++ b/target/linux/bcm4908/base-files/lib/upgrade/platform.sh @@ -0,0 +1,114 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause + +RAMFS_COPY_BIN="bcm63xx-bootfs" + +PART_NAME=firmware + +# $(1): file to read magic from +# $(2): offset in bytes +# $(3): length in bytes +get_content() { + dd if="$1" skip=$2 bs=1 count=$3 2>/dev/null +} + +platform_expected_image() { + local machine=$(board_name) + + case "$machine" in + "asus,gt-ac5300") echo "asus GT-AC5300"; return;; + "netgear,r8000p") echo "chk U12H359T00_NETGEAR"; return;; + "tplink,archer-c2300-v1") echo ""; return;; + esac +} + +platform_identify() { + local magic + local size + + size=$(wc -c "$1" | cut -d ' ' -f 1) + + magic=$(get_content "$1" $(($size - 20 - 64 + 8)) 12) + [ "$magic" = "GT-AC5300" ] && { + echo "asus" + return + } + + echo "unknown" +} + +platform_check_image() { + [ "$#" -gt 1 ] && return 1 + + local expected_image="$(platform_expected_image)" + local file_type=$(platform_identify "$1") + local error=0 + + case "$file_type" in + "asus") + local size=$(wc -c "$1" | cut -d ' ' -f 1) + local productid=$(get_content "$1" $(($size - 20 - 64 + 8)) 12) + + [ -n "$expected_image" -a "asus $productid" != "$expected_image" ] && { + echo "Firmware productid mismatch ($productid)" + error=1 + } + ;; + *) + echo "Invalid image type. Please use firmware specific for this device." + notify_firmware_broken + error=1 + ;; + esac + + return $error +} + +platform_calc_new_cferam() { + local mtd=$(find_mtd_part $PART_NAME) + [ -z "$mtd" ] && { + echo "Failed to find $PART_NAME partition" >&2 + return + } + + local idx=$(bcm63xx-bootfs ls $mtd | sed -n 's/cferam\.\(\d\d\d\)/\1/p') + [ -z "$idx" ] && { + echo "Failed to find cferam current index" >&2 + return + } + + idx=$(($idx + 1)) + [ "$idx" = "1000" ] && idx=0 + + echo $(printf "cferam.%03d" $idx) +} + +platform_img_from_asus_cmd() { + local size=$(wc -c "$1" | cut -d ' ' -f 1) + + # Use bs=1 to workaround missing iflag=count_bytes + echo -n dd bs=1 count=$(($size - 20 - 64)) +} + +platform_do_upgrade() { + local file_type=$(platform_identify "$1") + local cmd= + + # Find target cferam name + local cferam="$(platform_calc_new_cferam)" + [ -z "$cferam" ] && exit 1 + + bcm63xx-bootfs mv $1 cferam.000 $cferam || { + echo "Failed to rename cferam.000 to $cferam" >&2 + exit 1 + } + + # Flash new firmware + case "$file_type" in + "asus") cmd=$(platform_img_from_asus_cmd "$1");; + esac + mtd erase firmware + default_do_upgrade "$1" "$cmd" + + echo "SUCCESS! Used $cferam" +} -- 2.26.2 ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel
RE: [PATCH] bcm4908: implement basic sysupgrade support
Hi, > -Original Message- > From: openwrt-devel [mailto:openwrt-devel-boun...@lists.openwrt.org] > On Behalf Of Rafal Milecki > Sent: Dienstag, 23. März 2021 16:04 > To: openwrt-devel@lists.openwrt.org > Cc: Álvaro Fernández Rojas ; Rafał Miłecki > > Subject: [PATCH] bcm4908: implement basic sysupgrade support > > From: Rafał Miłecki > > It isn't UBI aware yet - that remains to be implemented. The usual nitpicks below ... [...] > --- /dev/null > +++ b/target/linux/bcm4908/base-files/lib/upgrade/platform.sh > @@ -0,0 +1,114 @@ > +#!/bin/sh Shebang can be dropped here (/lib und not execute bit) ... > +# SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause > + > +RAMFS_COPY_BIN="bcm63xx-bootfs" > + > +PART_NAME=firmware > + > +# $(1): file to read magic from > +# $(2): offset in bytes > +# $(3): length in bytes > +get_content() { > + dd if="$1" skip=$2 bs=1 count=$3 2>/dev/null } > + > +platform_expected_image() { > + local machine=$(board_name) > + > + case "$machine" in > + "asus,gt-ac5300") echo "asus GT-AC5300"; > return;; > + "netgear,r8000p") echo "chk > U12H359T00_NETGEAR"; return;; > + "tplink,archer-c2300-v1") echo ""; return;; > + esac > +} I don't think we need the "return" statements here? Apart from that, we don't need the quotes on the case vars (e.g. asus,gt-ac5300) either ... > + > +platform_identify() { > + local magic > + local size > + > + size=$(wc -c "$1" | cut -d ' ' -f 1) > + > + magic=$(get_content "$1" $(($size - 20 - 64 + 8)) 12) "$" can be dropped on "size". > + [ "$magic" = "GT-AC5300" ] && { > + echo "asus" > + return > + } > + > + echo "unknown" > +} One could modify this towards a case with default "unknown" (and drop the return again) ... > + > +platform_check_image() { > + [ "$#" -gt 1 ] && return 1 > + > + local expected_image="$(platform_expected_image)" > + local file_type=$(platform_identify "$1") > + local error=0 > + > + case "$file_type" in > + "asus") > + local size=$(wc -c "$1" | cut -d ' ' -f 1) > + local productid=$(get_content "$1" $(($size - 20 - 64 + > 8)) 12) "$" can be dropped on size ... > + > + [ -n "$expected_image" -a "asus $productid" != > "$expected_image" ] && { > + echo "Firmware productid mismatch > ($productid)" > + error=1 > + } > + ;; > + *) > + echo "Invalid image type. Please use firmware specific > for this device." > + notify_firmware_broken > + error=1 > + ;; > + esac > + > + return $error > +} > + > +platform_calc_new_cferam() { > + local mtd=$(find_mtd_part $PART_NAME) > + [ -z "$mtd" ] && { > + echo "Failed to find $PART_NAME partition" >&2 > + return > + } > + > + local idx=$(bcm63xx-bootfs ls $mtd | sed -n > 's/cferam\.\(\d\d\d\)/\1/p') > + [ -z "$idx" ] && { > + echo "Failed to find cferam current index" >&2 > + return > + } > + > + idx=$(($idx + 1)) "$" can be dropped on idx > + [ "$idx" = "1000" ] && idx=0 > + > + echo $(printf "cferam.%03d" $idx) > +} > + > +platform_img_from_asus_cmd() { > + local size=$(wc -c "$1" | cut -d ' ' -f 1) > + > + # Use bs=1 to workaround missing iflag=count_bytes > + echo -n dd bs=1 count=$(($size - 20 - 64)) } $size -> size Best Adrian > + > +platform_do_upgrade() { > + local file_type=$(platform_identify "$1") > + local cmd= > + > + # Find target cferam name > + local cferam="$(platform_calc_new_cferam)" > + [ -z "$cferam" ] && exit 1 > + > + bcm63xx-bootfs mv $1 cferam.000 $cferam || { > + echo "Failed to rename cferam.000 to $cferam" >&2 > + exit 1 > + } > + > + # Flash new firmware > + case "$file_type" in > + "asus") cmd=$(platform_img_from_asus_cmd "$1");; > + esac > + mtd erase firmware > + default_do_upgrade "$1" "$cmd" > + > + echo "SUCCESS! Used $cferam" > +} > -- > 2.26.2 > > > ___ > openwrt-devel mailing list > openwrt-devel@lists.openwrt.org > https://lists.openwrt.org/mailman/listinfo/openwrt-devel openpgp-digital-signature.asc Description: PGP signature ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel
Re: [PATCH] bcm4908: implement basic sysupgrade support
On 24.03.2021 19:10, Adrian Schmutzler wrote: The usual nitpicks below ... Thanks for review! + [ "$magic" = "GT-AC5300" ] && { + echo "asus" + return + } + + echo "unknown" +} One could modify this towards a case with default "unknown" (and drop the return again) ... In the future this function will need to check for various variables so a single case (switch) won't be an option. I've fixed all other pointed out places! ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel