From patchwork Sun Mar 27 20:05:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomasz Maciej Nowak X-Patchwork-Id: 1609924 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ExyO/Kpq; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=SFWLjv5s; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KRRl142Kqz9sCq for ; Mon, 28 Mar 2022 07:10:05 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=atCxJcx79HB28QixLdvJFDbbxieSO1EvNTwDnLaQp8c=; b=ExyO/KpqHjTHWJ cWJh+fXm7xG1eaB10U5486ZvuSdzbZwSTsGJYelvXpVGeC6kfCaD0zBumia+kkbgtCs1LHUuRA4em Uf8WMrWATuopU1BViE5iqFqKcx3TKtw7KcpgdRSq5x1SL4DUnoj2pO1jzWVE5DhBOPwhNw5s6G88C NNV/bqpgYQ6bvAb6qsgwnotFUnyYG44s79XQDP1e4ygtgVVmw18IaBEXCmBWBa80LYxI5imZoZ0O+ cyD6kSVH/szRAB7B8u3Yr+yCzJIXOqBBHGq6mpXMezH5v2+PcchxPSwYF2GE7m8iVYP7UXhSS1z0p FWYNDav1eEtxaBqyPEPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nYZB1-006BiM-Mt; Sun, 27 Mar 2022 20:07:52 +0000 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nYZ98-006B4h-2a for openwrt-devel@lists.openwrt.org; Sun, 27 Mar 2022 20:05:56 +0000 Received: by mail-lf1-x134.google.com with SMTP id m3so21451277lfj.11 for ; Sun, 27 Mar 2022 13:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=gFqhiabS6ZBROw0facyxdHF/YuiSgsec7ZU7qBir4wU=; b=SFWLjv5sn2tLSgE+OQeHcKJV8pydXYNRyedNVMdKWrol2nnxiM0ZblhGQM9BlJ/Xsq 9nWKGTXgROQ8V1PL7h1gW2V6QfhB7sqZxHFwZj+TxJjr2TXFbenTyPx60/Zrfsa7W0td ofFvNgTdPcTVIaSmN7Ay6IX6BccjE/NazuAllmhq6p9V1FRIE1sOamGtGCrhm+QMqoOO Clw1KrdgJRIU6In3GG8KO8xUTetOifnyKck3T8Mac87Ihk3DrKPsUGvpXQOmvb5c2DhT V9yMlRAwSohgExmCU1VeHcEGZaY7x6KxpoLNVcZq3HStc+6zjpdYHW2rPibVP4Ado9s/ iIRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gFqhiabS6ZBROw0facyxdHF/YuiSgsec7ZU7qBir4wU=; b=1vkzR9asAcGTwpC5DwgmDYnY18E2k7Rmsy9VrZaKOztQe5arNTQO6EWApIlGhW/zst 3u37Dq8ORQjEkTqo5GmYiLcmnL92MBgQJrnpTDzTeAtD8xhfqb5Lw8dC6lPZb2wtA9xK EKspMju5VVY50QUPHuuotTr8EnRgzP1HLufGgZFla0XjGZvfuObojZOUz2omw1p2JWWt yZvKiYv7VglspdcKcHXrCwC4jtS4Jw4xNvnAnnsFF4Mc3L2CXd8dMeIgLeztL2uTuN9B lSpeW2Te3HfaooWZ4p0yIXXfbKl+yaxRwQb3drqTXrPV3rLKC+iL7VrgTtXqkKPnv1gQ MCCw== X-Gm-Message-State: AOAM530K4UmYiaVBpg3b3bD/YLUN5vzCDNDKaGkMsOFcCyVkcWmo4IBt JWtlNrvLSgl2E6z3XzvFc0JaCssFIBkkmw== X-Google-Smtp-Source: ABdhPJxvMh/ItYOHQjcKIJ5cR8ACe6LrhTwx1huVbH2/QnMYYMa3wwPVEV3fy1hSd6jWmyHyM9djuw== X-Received: by 2002:ac2:51c6:0:b0:44a:5e41:b284 with SMTP id u6-20020ac251c6000000b0044a5e41b284mr16184080lfm.582.1648411552466; Sun, 27 Mar 2022 13:05:52 -0700 (PDT) Received: from localhost.localdomain ([212.106.161.171]) by smtp.googlemail.com with ESMTPSA id i3-20020a198c43000000b00448a1566977sm1440445lfj.275.2022.03.27.13.05.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Mar 2022 13:05:52 -0700 (PDT) From: Tomasz Maciej Nowak To: openwrt-devel@lists.openwrt.org Subject: [PATCH v2 3/7] ath79: move image check for devices with RedBoot Date: Sun, 27 Mar 2022 22:05:30 +0200 Message-Id: <20220327200534.377029-4-tmn505@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220327200534.377029-1-tmn505@gmail.com> References: <20220327200534.377029-1-tmn505@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220327_130554_151656_DA4F433B X-CRM114-Status: GOOD ( 15.91 ) X-Spam-Score: 0.1 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Don't comence the switch to RAMFS when the image format is wrong. This led to rebooting the device, which could lead to false impression that upgrade succeded. Being here, factor out the code responsi [...] Content analysis details: (0.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:134 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [tmn505[at]gmail.com] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [tmn505[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Don't comence the switch to RAMFS when the image format is wrong. This led to rebooting the device, which could lead to false impression that upgrade succeded. Being here, factor out the code responsible for upgrading RedBoot devices to separate file. Signed-off-by: Tomasz Maciej Nowak --- .../base-files/lib/upgrade/platform.sh | 46 ++++++------------- .../base-files/lib/upgrade/redboot-fis.sh | 31 +++++++++++++ 2 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 target/linux/ath79/generic/base-files/lib/upgrade/redboot-fis.sh diff --git a/target/linux/ath79/generic/base-files/lib/upgrade/platform.sh b/target/linux/ath79/generic/base-files/lib/upgrade/platform.sh index 642a9891ff29..f161540a6877 100644 --- a/target/linux/ath79/generic/base-files/lib/upgrade/platform.sh +++ b/target/linux/ath79/generic/base-files/lib/upgrade/platform.sh @@ -8,35 +8,19 @@ REQUIRE_IMAGE_METADATA=1 RAMFS_COPY_BIN='fw_printenv fw_setenv' RAMFS_COPY_DATA='/etc/fw_env.config /var/lock/fw_printenv.lock' -redboot_fis_do_upgrade() { - local append - local sysup_file="$1" - local kern_part="$2" - local magic=$(get_magic_word "$sysup_file") - - if [ "$magic" = "7379" ]; then - local board_dir=$(tar tf $sysup_file | grep -m 1 '^sysupgrade-.*/$') - - [ -f "$UPGRADE_BACKUP" ] && append="-j $UPGRADE_BACKUP" - - if grep -q "mtd1.*loader" /proc/mtd; then - tar xf $sysup_file ${board_dir}kernel ${board_dir}root -O | \ - mtd -r $append write - loader:firmware - - else - local kern_length=$(tar xf $sysup_file ${board_dir}kernel -O | wc -c) - - tar xf $sysup_file ${board_dir}kernel ${board_dir}root -O | \ - mtd -r $append -F$kern_part:$kern_length:0x80060000,rootfs write - $kern_part:rootfs - fi - else - echo "Unknown image, aborting!" - return 1 - fi -} - platform_check_image() { - return 0 + local board=$(board_name) + + case "$board" in + jjplus,ja76pf2|\ + ubnt,routerstation|\ + ubnt,routerstation-pro) + platform_check_image_redboot_fis "$1" + ;; + *) + return 0 + ;; + esac } platform_do_upgrade() { @@ -45,7 +29,7 @@ platform_do_upgrade() { case "$board" in adtran,bsap1800-v2|\ adtran,bsap1840) - redboot_fis_do_upgrade "$1" vmlinux_2 + platform_do_upgrade_redboot_fis "$1" vmlinux_2 ;; allnet,all-wap02860ac|\ araknis,an-300-ap-i-n|\ @@ -66,7 +50,7 @@ platform_do_upgrade() { platform_do_upgrade_failsafe_datachk "$1" ;; jjplus,ja76pf2) - redboot_fis_do_upgrade "$1" linux + platform_do_upgrade_redboot_fis "$1" linux ;; openmesh,a40|\ openmesh,a60|\ @@ -98,7 +82,7 @@ platform_do_upgrade() { ;; ubnt,routerstation|\ ubnt,routerstation-pro) - redboot_fis_do_upgrade "$1" kernel + platform_do_upgrade_redboot_fis "$1" kernel ;; *) default_do_upgrade "$1" diff --git a/target/linux/ath79/generic/base-files/lib/upgrade/redboot-fis.sh b/target/linux/ath79/generic/base-files/lib/upgrade/redboot-fis.sh new file mode 100644 index 000000000000..f45d9a2e790e --- /dev/null +++ b/target/linux/ath79/generic/base-files/lib/upgrade/redboot-fis.sh @@ -0,0 +1,31 @@ +platform_check_image_redboot_fis() { + if [ "$(get_magic_word "$1")" != "7379" ]; then + v "Unknown image format, aborting!" + return 1 + else + return 0 + fi +} + +platform_do_upgrade_redboot_fis() { + local append + local sysup_file="$1" + local kern_part="$2" + + if [ "$(get_magic_word "$sysup_file")" = "7379" ]; then + local board_dir=$(tar tf $sysup_file | grep -m 1 '^sysupgrade-.*/$') + + [ -f "$UPGRADE_BACKUP" ] && append="-j $UPGRADE_BACKUP" + + if grep -q "mtd1.*loader" /proc/mtd; then + tar xf $sysup_file ${board_dir}kernel ${board_dir}root -O | \ + mtd -r $append write - loader:firmware + + else + local kern_length=$(tar xf $sysup_file ${board_dir}kernel -O | wc -c) + + tar xf $sysup_file ${board_dir}kernel ${board_dir}root -O | \ + mtd -r $append -F$kern_part:$kern_length:0x80060000,rootfs write - $kern_part:rootfs + fi + fi +}