From patchwork Thu Jul 9 18:14:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Schmutzler X-Patchwork-Id: 1326130 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=atkznbYA; 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 4B2ktT4Qfmz9sRN for ; Fri, 10 Jul 2020 04:17:53 +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=fklMnoNwXmUNojQ8HwGs8GAxkWQb0EE2VIZGMCbBKRc=; b=atkznbYAOFwvYGpnbuJNlw4hNk T1pVmEijFvcrxK6zKnYYyDWcHmlwyNXZ0BzT3VpUkokNuMmz4hnSGq5zC/CAp1uspUP4zcFvOstTq NOUZCcc8+K4vg31VqGminJXDhCKCKtDXgfZNu2subDbNaERfqzYPm6ba0eW3Zwwc2Z9ZK33rdj2zC zocXoHdJ6Af7U0IM0k6SZg4xwY8CvSram1WxdsL5Yw3lCKWzzgYIlrwLCKPTkuXX0yIrTYjO4Eu+G Xdrn85XvLae3b4A1AiNziWaZExLOxuTaaJXEFNw0QRCSEg79y0f54+J0OmxfR/Ydio6X5Y7qhZsmr dA8+CetQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtb5Q-0000CZ-FW; Thu, 09 Jul 2020 18:15:56 +0000 Received: from mout.kundenserver.de ([212.227.126.187]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtb5J-00009r-Uk for openwrt-devel@lists.openwrt.org; Thu, 09 Jul 2020 18:15:51 +0000 Received: from buildfff.adridolf.com ([188.192.134.246]) by mrelayeu.kundenserver.de (mreue009 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mn2eN-1kZprU3S1H-00k4x9 for ; Thu, 09 Jul 2020 20:15:43 +0200 From: Adrian Schmutzler To: openwrt-devel@lists.openwrt.org Subject: [PATCH 3/5] base-files: fwtool: implement compatibility check for images Date: Thu, 9 Jul 2020 20:14:58 +0200 Message-Id: <20200709181500.10948-4-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:ZvFivMXPVydeF/MOsup3o+Z9wo8o6f095qWxaFRcEp1Ho+oC74e r3RrjRugynRTHqPjlQA3V77CY4/OJ16IWPE0Bd9uyIhPM2CSm+fHmNBxVpsfxl0I1YwHtGD 79kZK37M1km2FtLa5LR+EUhJ26Rl3q4uSiaNZVbNsdgSVNnutZSBr9lcvY8wcq/CPGjdVyf FjPHFKjcOmp6NVqiu1xdw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:ZwD4oUSKPbg=:VNLmkevfAx/gef2vfsMb+W RltA/isQhAdqfE73osRCmkajqP0/vh7gPiyLLnaLrw3Rk/5UOn6GF2j2j5FLnQATz4ohDPjh4 tlHpaoB3l5Vyp/ODZGdZXG1yMRHrfcbFYJLF+0yKfff1aBuL9Mcjq2tQkMz6hKK9mXlanS8XR gOkGQfgTBtO1PybBZbwU7x82wNuqia/LC7GO1jVX4oV15x6gIQcLjRkNxmTP+HRDXaY4Qcr9s ZX9BJYY8RIsPQjCb8oi1Rlewra3rxCkaLmeKd2lrFBq2XgJJkZj+w4F+UQUI3AqvQiUpjRq6Z HQM6uwv+Uylt70vDogjfSr9rdLHusBnUMUToPKTRpqF08S5NzKORk+D/Ti1EUnxqptgQjxclM eRKlqlma+lga4PX8n31I6xuk97vUJhlyzz3WOjIsqtTOBD+SautTaW93Z3y153gO63Ij4UVQt yQuSHbQVA42HcBVOC7A03/7GcxGdo4d4apagcNc9I4bd+rZ1J6E8pp2h0LhXKMc/AOT6xGVVf VYCqEEua7byfeN5Mis1Pyk20KfvCbqsCd0f879MrGXO+1E70TgMWKIZoFN6jefuwnLuIsfD00 8vw/t86jHjG8YHB7zBoWHhi72+/g/X6bmmbDVqndtr+81ty902Hh9SkG+/cCmup04hTgThcbB 4RqXpBksNhcU+w6lENbCFe6xqho4OiBBTIfc+rhO0oESn185PMbpNsxk5KTFG9WF/UzwvhNxH JUfuZankiDyZyFvBj8WmPqAjvFTNk4Zol1ytE0H3ouZVTLXmWG3uZyyX7JH+/DJ2g3ckA4f04 Xl3mHobwZln1E4ZbAjXIR5QAgR0iMM4zom7n67l1cWb5+Td4AJeaE/Lqk2psh3B91gjcrDrhz NXtOit4KizPEqJpIC6Zw== X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200709_141550_265407_741732C7 X-CRM114-Status: GOOD ( 10.64 ) 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.187 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [212.227.126.187 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 We regularly encounter the situation that devices are subject to changes that will make them incompatible to previous versions. Removing SUPPORTED_DEVICES will not really be helpful in most of these cases, as this only helps after a rename. To solve this situation, this patchset introduces a compatibility version for devices. In this patch, the actual checks are implemented into fwtool_check_image(): If an incompatible change is introduced, one can increase either the minor version (1.0->1.1) or the major version (1.0->2.0). Minor version increment: This will still allow sysupgrade, but require to reset config (-n or SAVE_CONFIG=0). If sysupgrade is called without -n, a corresponding message will be printed. If sysupgrade is called with -n, it will just pass, with supported devices being checked as usual. (Which will allow us to add back SUPPORTED_DEVICES for many cases.) Major version increment: This is meant for potential (rare) cases where sysupgrade is not possible at all, because it would break the device. In this case, a warning will be printed, and -n won't help. If image check fails because of one of the versions parts not matching, the content of DEVICE_COMPAT_MESSAGE is printed in addition to the generic message (if set). For both cases, upgrade can still be forced with -F as usual. Signed-off-by: Adrian Schmutzler --- .../base-files/files/lib/upgrade/fwtool.sh | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/package/base-files/files/lib/upgrade/fwtool.sh b/package/base-files/files/lib/upgrade/fwtool.sh index a0b3fb0a04..dc064fee80 100644 --- a/package/base-files/files/lib/upgrade/fwtool.sh +++ b/package/base-files/files/lib/upgrade/fwtool.sh @@ -44,6 +44,26 @@ fwtool_check_image() { } device="$(cat /tmp/sysinfo/board_name)" + devicecompat="$(uci -q get system.@system[0].compat_version)" + [ -n "$devicecompat" ] || devicecompat="1.0" + + json_get_var imagecompat compat_version + json_get_var compatmessage compat_message + [ -n "$imagecompat" ] || imagecompat="1.0" + + # major compat version -> no sysupgrade + if [ "${devicecompat%.*}" != "${imagecompat%.*}" ]; then + echo "This image is incompatible for sysupgrading based on the image version." + [ -n "$compatmessage" ] && echo "$compatmessage" + return 1 + fi + + # minor compat version -> sysupgrade with -n required + if [ "${devicecompat#.*}" != "${imagecompat#.*}" ] && [ "$SAVE_CONFIG" = "1" ]; then + echo "This config is incompatible to the new image. Please upgrade with -n" + [ -n "$compatmessage" ] && echo "$compatmessage" + return 1 + fi json_select supported_devices || return 1