From patchwork Thu Jul 9 18:14:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Schmutzler X-Patchwork-Id: 1326133 X-Patchwork-Delegate: freifunk@adrianschmutzler.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=adrianschmutzler.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=J5BR5pi6; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (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 ozlabs.org (Postfix) with ESMTPS id 4B2ktf6TcWz9sRf for ; Fri, 10 Jul 2020 04:18:02 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; 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=SUzjTWJrCOqJa6uMeTDfucj1Lo6TKJ6OQ7T2XTU4uvA=; b=J5BR5pi6JdALCOAtJotVdpB+r/ lckOjwh/PYy25aAX1iD1kvbG4XTacEJM4U4cNxFQzlEP1oczmpuvmubA2CoVzU/SX+yZoyfQ8VQbD 4e8LCG8CMynS5PQWgzHQmPC1qILCFEwHip4VAVZt+wMC57cUj3ZDmYb5efPjmm9g8+5v3qnEGORsU IC4KTzncb/2R5ln8PiE9zIK13uxPQJ4Ka0gM8rfnDOQLvHku+mZME2Z/RS+/biOq0N2LCdv3pmqMn R2hrNB2n/3dGtHVMuxw+bHNCDeZynC4h44vuy1PKJr6SocPm/6uPTQZPvWgpJ5lRDCbEsQSdh/oNz PCqcLJVg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtb5L-0000Bi-VG; Thu, 09 Jul 2020 18:15:52 +0000 Received: from mout.kundenserver.de ([212.227.126.133]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtb5I-000094-E7 for openwrt-devel@lists.openwrt.org; Thu, 09 Jul 2020 18:15:49 +0000 Received: from buildfff.adridolf.com ([188.192.134.246]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MjjGV-1kd8BI3wSJ-00lBx1 for ; Thu, 09 Jul 2020 20:15:44 +0200 From: Adrian Schmutzler To: openwrt-devel@lists.openwrt.org Subject: [PATCH 4/5] base-files: fwtool: make compat_version backward compatible Date: Thu, 9 Jul 2020 20:14:59 +0200 Message-Id: <20200709181500.10948-5-freifunk@adrianschmutzler.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200709181500.10948-1-freifunk@adrianschmutzler.de> References: <20200709181500.10948-1-freifunk@adrianschmutzler.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:9NWRX4ZXFZvIl5AsoebF21qwAZV3S9peEgWOeqSzfJxl6VqRbDx /9hfWHYTulwAh1V7/9f0FOp9ZwBKypAI+RiIMSYAgZfjpZKswgaoaNS5jGlGK6Evw6H7GYE QgOYKgvaZM6e2JOPLuAeQ56SLFjOAEYLF1fRNtv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) MR-646709E3 X-CRM114-CacheID: sfid-20200709_141548_689628_5E30404F X-CRM114-Status: GOOD ( 11.46 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [212.227.126.133 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [212.227.126.133 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 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 So far, the compatibility mechanism only works if both device and image are already updated to the new routines. This patch extends the sysupgrade metadata and fwtool_check_image() to account for "older" images as well: The basic mechanism for older devices to check for image compatibility is the supported_devices entry. This can be exploited by putting a custom message into this variable of the metadata, so older FW will produce a mismatch and print the message as it thinks it's the list of supported devices. So, we have two cases: device 1.0, image 1.0: The metadata will just contain supported_devices as before. device 1.0, image 1.1: The metadata will contain: "new_supported_devices":["device_string1", "device_string2", ...], "supported_devices":["Upgrade incompatible. Please check Wiki ..."] If the device is "legacy", i.e. does not have the updated fwtool.sh, it will just fail with image check and print the content of supported_devices. Upgrade can still be performed with -F like when SUPPORTED_DEVICES has been removed to prevent bricking. If the device has updated fwtool.sh (but is 1.0), it will just use the new_supported_devices instead, and work as intended (flashing with -n will work, flashing without will print the appropriate warning). This mechanism should provide a fair tradeoff between simplicity and functionality. Signed-off-by: Adrian Schmutzler --- include/image-commands.mk | 4 +++- package/base-files/files/lib/upgrade/fwtool.sh | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/image-commands.mk b/include/image-commands.mk index 9da712e733..42e735314b 100644 --- a/include/image-commands.mk +++ b/include/image-commands.mk @@ -393,7 +393,9 @@ metadata_json = \ "metadata_version": "1.0", \ "compat_version": "$(call json_quote,$(compat_version))", \ $(if $(DEVICE_COMPAT_MESSAGE),"compat_message": "$(call json_quote,$(DEVICE_COMPAT_MESSAGE))"$(comma)) \ - "supported_devices":[$(call metadata_devices,$(SUPPORTED_DEVICES))], \ + $(if $(filter-out 1.0,$(compat_version)),"new_supported_devices":[$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma)) \ + $(if $(filter-out 1.0,$(compat_version)),"supported_devices":["$(call json_quote,Upgrade incompatible. Please check Wiki ...)"]$(comma)) \ + $(if $(filter 1.0,$(compat_version)),"supported_devices":[$(call metadata_devices,$(SUPPORTED_DEVICES))]$(comma)) \ "version": { \ "dist": "$(call json_quote,$(VERSION_DIST))", \ "version": "$(call json_quote,$(VERSION_NUMBER))", \ diff --git a/package/base-files/files/lib/upgrade/fwtool.sh b/package/base-files/files/lib/upgrade/fwtool.sh index dc064fee80..f622e8bd71 100644 --- a/package/base-files/files/lib/upgrade/fwtool.sh +++ b/package/base-files/files/lib/upgrade/fwtool.sh @@ -65,7 +65,12 @@ fwtool_check_image() { return 1 fi - json_select supported_devices || return 1 + # select correct supported list based on compat_version + # (using this ensures that compatibility check works for devices + # not knowing about compat-version) + local supported=supported_devices + [ "$imagecompat" != "1.0" ] && supported=new_supported_devices + json_select $supported || return 1 json_get_keys dev_keys for k in $dev_keys; do