From patchwork Tue Jul 14 14:28:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Schmutzler X-Patchwork-Id: 1328930 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=Qkk1lalY; 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 4B5jdK3RyGz9sRW for ; Wed, 15 Jul 2020 00:31:49 +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=NrGmE+NkHpcNIS6gjKwQ6IMP/njZ7e0ZTaKiCcDYzSk=; b=Qkk1lalYaa9G3Bq6cYRJeL6Y1B 0i8mK+ynuopayNO+Dbz4n4K/n8OnhSTcg2jwZHd4iIr8RG6yG3oQ99Sa1QxNUxqe/dtfDEl5f2S00 nw99dwK+6UG9WiXAV6i1q86Ab/8PnEjqpJjL84vGcdSme/XpKf9UZmhjNuDyUyd+lBsKYMtLdyuK7 P9w91C/mhoPOPJ/2ROEfjLD8toDBF2sOn9CgKKuuK5Vi6i0km0DN7wYpP743ooX6FUQr6qXG0dgHk EgTD7rsgfHHdA6PY008Ciibg7h/q2SU4AuAePFieflK3F3qpa/9yrxQXNl5s0og5zqLPa7G8Gqmij dJ5U87jw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvLvt-0000KO-5K; Tue, 14 Jul 2020 14:29:21 +0000 Received: from mout.kundenserver.de ([217.72.192.73]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jvLvn-0000FU-Ki for openwrt-devel@lists.openwrt.org; Tue, 14 Jul 2020 14:29:17 +0000 Received: from buildfff.adridolf.com ([188.192.134.246]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MEVBc-1k6xpt3IbK-00FyMF for ; Tue, 14 Jul 2020 16:29:11 +0200 From: Adrian Schmutzler To: openwrt-devel@lists.openwrt.org Subject: [PATCH v2 4/6] base-files: fwtool: make compat_version backward compatible Date: Tue, 14 Jul 2020 16:28:23 +0200 Message-Id: <20200714142825.16889-5-freifunk@adrianschmutzler.de> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200714142825.16889-1-freifunk@adrianschmutzler.de> References: <20200714142825.16889-1-freifunk@adrianschmutzler.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:xy5oeS7eP2LhTR1DAdY0fKNmXdvUPB4U9W9yYwdpwvfU1KN52tO VXy12BzAXFIQGLHakmZkEh7cEQXh87KlPGnNFrvfVQXkgEz6BYIu1YNBFd3RTyd9Bjobp+V jT4nyeV3yZbbhqW56yA3LlWfYEMFCiZklfa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BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200714_102915_916096_3BCD0A95 X-CRM114-Status: GOOD ( 12.88 ) 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 [217.72.192.73 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [217.72.192.73 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an 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 --- Changes in v2: - Add DEVICE_COMPAT_MESSAGE and reword comment for legacy warning. --- include/image-commands.mk | 5 ++++- package/base-files/files/lib/upgrade/fwtool.sh | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/image-commands.mk b/include/image-commands.mk index 9da712e733..e21472a659 100644 --- a/include/image-commands.mk +++ b/include/image-commands.mk @@ -393,7 +393,10 @@ 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,Image version $(compat_version) incompatible to device: $(if $(DEVICE_COMPAT_MESSAGE),$(DEVICE_COMPAT_MESSAGE),Please check documentation ...)"]$(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 1807aecd6d..59f981f6c3 100644 --- a/package/base-files/files/lib/upgrade/fwtool.sh +++ b/package/base-files/files/lib/upgrade/fwtool.sh @@ -51,7 +51,12 @@ fwtool_check_image() { json_get_var compatmessage compat_message [ -n "$imagecompat" ] || imagecompat="1.0" - 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