[PATCH] bcm4908: implement basic sysupgrade support
Adrian Schmutzler
mail at adrianschmutzler.de
Wed Mar 24 18:10:06 GMT 2021
Hi,
> -----Original Message-----
> From: openwrt-devel [mailto:openwrt-devel-bounces at lists.openwrt.org]
> On Behalf Of Rafal Milecki
> Sent: Dienstag, 23. März 2021 16:04
> To: openwrt-devel at lists.openwrt.org
> Cc: Álvaro Fernández Rojas <noltari at gmail.com>; Rafał Miłecki
> <rafal at milecki.pl>
> Subject: [PATCH] bcm4908: implement basic sysupgrade support
>
> From: Rafał Miłecki <rafal at milecki.pl>
>
> 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 at lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: openpgp-digital-signature.asc
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20210324/597c474e/attachment.sig>
More information about the openwrt-devel
mailing list