From patchwork Sat Jan 23 10:08:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Bj=C3=B8rn_Mork?= X-Patchwork-Id: 1430659 X-Patchwork-Delegate: ynezz@true.cz 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; 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=eLgy4MeV; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=mork.no header.i=@mork.no header.a=rsa-sha256 header.s=b header.b=jD5d7Kn1; 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 4DNBh6511jz9rx8 for ; Sat, 23 Jan 2021 21:09:58 +1100 (AEDT) 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:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=O/t63UVVEYUeJhmUPyrtdtxQR4BPNwfkZc7VCoq19jI=; b=eLgy4MeVuiVJZhLa0rocky0ko hBvVE7JQRuL89BULOO1ditcblhUnK+yDLcd8+Skg3sgGYNYChfQtz3P0pFwDwYzZdsHYOW5Ka8blX KXia2t2mYqdYEcaIWkBKEVXrfvnMYu0oHRd2JFIJrjQRhJQN6oWpfDKEQFVK7gtpPOqOivaJaexvW aHbyHe/zzGFAEH542izN15wpWJ9MAlm3iCjD8gq2mgNKBKdIR/TfalkcvCX8MQw8KiHPlpdaePtG6 hGX2xIPAhzHK7pQy4p65+DJAFPJz79rUs8bGDwgvbfRBdW7gSq7+NuCT7k70CALuEx2wySe3gpD2e TYU/JCPMA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l3FqC-0001E8-NH; Sat, 23 Jan 2021 10:08:24 +0000 Received: from canardo.mork.no ([2001:4641::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l3Fq7-0001Bn-Ey for openwrt-devel@lists.openwrt.org; Sat, 23 Jan 2021 10:08:20 +0000 Received: from canardo.mork.no (ip6-localhost [IPv6:0:0:0:0:0:0:0:1]) by canardo.mork.no (8.15.2/8.15.2) with ESMTPS id 10NA8FQS005214 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Sat, 23 Jan 2021 11:08:15 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1611396495; bh=3EsMl2L3k/rs5md2jqlednqU5SSqoXQDqJdza6FmJNw=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=jD5d7Kn1Y78RbVm+uJhYlM7PtsfyIoLlgwOCfxVTsZzcuzQVodqV2J3eGeVR7G4+7 yjnWydXD8qXaxIj8FS6QhLgefLJgSi8EUa2Zi9StMHYT1sOuzwMMQiBfTZ4RrDuEky sZ9go2ROTiuTJMmg4W607dH+7vjALXZoVsJIWFBw= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 10NA8FPH005206; Sat, 23 Jan 2021 11:08:15 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH 1/2] realtek: use vendor-specific magic for ZyXEL Date: Sat, 23 Jan 2021 11:08:11 +0100 Message-Id: <20210123100812.5158-2-bjorn@mork.no> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210123100812.5158-1-bjorn@mork.no> References: <20210123100812.5158-1-bjorn@mork.no> MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on canardo.mork.no X-Virus-Scanned: clamav-milter 0.102.4 at canardo X-Virus-Status: Clean X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210123_050819_827652_3422C844 X-CRM114-Status: GOOD ( 11.22 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2001:4641:0:0:0:0:0:1 listed in] [list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -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.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Bj=C3=B8rn_Mork?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org The stock firmware of the ZyXEL GS1900 series use a non-standard u-image magic. This is not enforced by the stock u-boot, which is why we could boot images with the default magic. The flash management application of the stock firmware will however verify the magic, and refuse any image with another value. Convert to vendor-specific value to get flash management support in stock firmware, including the ability to upgrade to OpenWrt directly from stock web UI. Signed-off-by: Bjørn Mork --- target/linux/realtek/dts/rtl8380_zyxel_gs1900.dtsi | 3 ++- target/linux/realtek/image/Makefile | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/target/linux/realtek/dts/rtl8380_zyxel_gs1900.dtsi b/target/linux/realtek/dts/rtl8380_zyxel_gs1900.dtsi index 5f06339d13bf..c4441ec30eef 100644 --- a/target/linux/realtek/dts/rtl8380_zyxel_gs1900.dtsi +++ b/target/linux/realtek/dts/rtl8380_zyxel_gs1900.dtsi @@ -92,7 +92,8 @@ partition@b260000 { label = "firmware"; reg = <0x260000 0x6d0000>; - compatible = "denx,uimage"; + compatible = "openwrt,uimage", "denx,uimage"; + openwrt,ih-magic = <0x83800000>; }; partition@930000 { label = "runtime2"; diff --git a/target/linux/realtek/image/Makefile b/target/linux/realtek/image/Makefile index 1251b47c933d..c0ae8be36d98 100644 --- a/target/linux/realtek/image/Makefile +++ b/target/linux/realtek/image/Makefile @@ -70,6 +70,7 @@ define Device/zyxel_gs1900-10hp IMAGE_SIZE := 6976k DEVICE_VENDOR := ZyXEL DEVICE_MODEL := GS1900-10HP + UIMAGE_MAGIC := 0x83800000 endef TARGET_DEVICES += zyxel_gs1900-10hp @@ -80,6 +81,7 @@ define Device/zyxel_gs1900-8hp-v1 DEVICE_MODEL := GS1900-8HP DEVICE_VARIANT := v1 DEVICE_PACKAGES += lua-rs232 + UIMAGE_MAGIC := 0x83800000 endef TARGET_DEVICES += zyxel_gs1900-8hp-v1 @@ -90,6 +92,7 @@ define Device/zyxel_gs1900-8hp-v2 DEVICE_MODEL := GS1900-8HP DEVICE_VARIANT := v2 DEVICE_PACKAGES += lua-rs232 + UIMAGE_MAGIC := 0x83800000 endef TARGET_DEVICES += zyxel_gs1900-8hp-v2 From patchwork Sat Jan 23 10:08:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Bj=C3=B8rn_Mork?= X-Patchwork-Id: 1430661 X-Patchwork-Delegate: ynezz@true.cz 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; 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=H0PHDiPX; dkim=fail reason="signature verification failed" (1024-bit key; secure) header.d=mork.no header.i=@mork.no header.a=rsa-sha256 header.s=b header.b=Ob6bqF7v; 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 4DNBhB0TLhz9sS8 for ; Sat, 23 Jan 2021 21:10:02 +1100 (AEDT) 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:Cc: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:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=TSlmmvvWdx7eYjcSxfQB2HKTKnAuA6wJHmYrbVyVcxc=; b=H0PHDiPXugHQxpnnrW4aqPJpc Km8XpZSLa0smCR8i5BkvZb+33VM+l4HKvp0Zz/4Nnje9OL5PzzQtOFhXyLqxr8yS9oREhvh92wg1T hL1/80ifkfMzLjFISs7GAfbD0emLcPgbQ0HNUPmzC4v17ohBvYhZhnPOk/NicRxqEbcOuAkzvNJiy r+miMYiMS2hjm+Z6RhgiH7FR1aFaCBhhGoVDTCMiXhOFnL5g+9RKMklqVdzY/2QgfuDUd2cWex0R6 030xGQ8zYQHpfYtxpPySH9ZHcm6xdPkRe6vDF7i1WdDr8O5jC5OYLDFGEXZovL5ivkLA9N63dcAzr rqHmT/rAQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l3FqH-0001FR-Jf; Sat, 23 Jan 2021 10:08:29 +0000 Received: from canardo.mork.no ([2001:4641::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l3Fq7-0001Bt-EW for openwrt-devel@lists.openwrt.org; Sat, 23 Jan 2021 10:08:22 +0000 Received: from canardo.mork.no (ip6-localhost [IPv6:0:0:0:0:0:0:0:1]) by canardo.mork.no (8.15.2/8.15.2) with ESMTPS id 10NA8Fel005237 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=OK); Sat, 23 Jan 2021 11:08:15 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mork.no; s=b; t=1611396495; bh=69FQKibq3iyt97L+8Crs840JNIjLFLI0s/m3jHvepBQ=; h=From:To:Cc:Subject:Date:Message-Id:References:From; b=Ob6bqF7vaGZ9PTpjDrpCzn+TAl5QZYJW5yAk4Gs0dOi3+0iw6Txtirkga/g9w+Vsh +p7OTe3Lglb8KD2+W8bdLPj5yBb3uLeETylC5jTkfuv41Psxun1BFWXpJlZ0TJT2hX Dre7Tx5B6/VhLlYg4yaqsQYK2pyeALPokDn3dSaA= Received: (from bjorn@localhost) by canardo.mork.no (8.15.2/8.15.2/Submit) id 10NA8FcU005228; Sat, 23 Jan 2021 11:08:15 +0100 From: =?utf-8?q?Bj=C3=B8rn_Mork?= To: openwrt-devel@lists.openwrt.org Subject: [PATCH 2/2] realtek: build ZyXEL vendor firmware compatible initramfs Date: Sat, 23 Jan 2021 11:08:12 +0100 Message-Id: <20210123100812.5158-3-bjorn@mork.no> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210123100812.5158-1-bjorn@mork.no> References: <20210123100812.5158-1-bjorn@mork.no> MIME-Version: 1.0 X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on canardo.mork.no X-Virus-Scanned: clamav-milter 0.102.4 at canardo X-Virus-Status: Clean X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210123_050819_828006_92ED5532 X-CRM114-Status: GOOD ( 13.42 ) X-Spam-Score: -2.5 (--) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-2.5 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2001:4641:0:0:0:0:0:1 listed in] [list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -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.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Bj=C3=B8rn_Mork?= Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Append a device specific version trailer used by the stock firmware upgrade application to validate firmwares. The trailer contains a list of ZyXEL firmware version numbers, which includes a four letter hardware identifier. The stock web UI requires that the current hardware matches one of the listed versions, and that the version number is larger than a model specific minimum value. The minimum version varies between V1.00 and V2.60 for the currently known GS1900 models. The number is not used anywhere else to our knowlege, and has no direct relation to the version info in the u-image header. We can therefore use an arbitrary value larger than V2.60. The stock firmware upgrade application will only load and flash the part of the file specified in the u-image header, regardless of file size. It can therefore not be used to flash images with an appended rootfs. There is therefore no need to include the trailer in other images than the initramfs. This prevents accidentally bricking by attempts to flash other images from the stock web UI. Stock images support all models in the series, listing all of them in the version trailer. OpenWrt provide model specific images. We therefore only list the single supported hardware identifier for each image. This eliminates the risk of flashing the wrong OpenWrt image from stock web UI. OpenWrt can be installed from stock firmware in two steps: 1) flash OpenWrt initramfs image from stock web gui 2) boot OpenWrt and sysupgrade to a squasfs image The OpenWrt squashfs image depends on a static partition map in the DTS. It can only be installed to the "firmware" partition. This partition is labeled "RUNTIME1" in u-boot and in stock firmware, and is referred to as "image 0" in the stock flash management tool. The OpenWrt initramfs can be installed and run from either partitions. But if you want to keep stock irmware in the spare system partition, then you must make sure stock firmware is installed to the "RUNTIME2" partition referred to as "image 1" in the stock web UI. And the initial OpenWrt initramfs must be flashed to "RUNTIME1"/"image 0". The stock flash management application supports direct selection of both which partition to flash and which partition to boot next. This allows software controlled "dual-boot" between OpenWrt and stock firmware, without using console access to u-boot. u-boot use the "bootpartition" variable stored in the second u-boot environment to select which of the two system partitions to boot. This variable is set by the stock flash management application, by direct user input. It can also be set in OpenWrt using e.g fw_setsys bootpartition 1 to select "RUNTIME2"/"image 1" as default, assuming a stock firmware version is installed in that partition. Signed-off-by: Bjørn Mork --- target/linux/realtek/image/Makefile | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/target/linux/realtek/image/Makefile b/target/linux/realtek/image/Makefile index c0ae8be36d98..e1716a95a571 100644 --- a/target/linux/realtek/image/Makefile +++ b/target/linux/realtek/image/Makefile @@ -7,6 +7,14 @@ include $(INCLUDE_DIR)/image.mk KERNEL_LOADADDR = 0x80000000 KERNEL_ENTRY = 0x80000400 +define Build/zyxel-vers + ( echo VERS;\ + for hw in $(1); do\ + echo -n "V9.99($$hw.0) | ";\ + date -d @$(SOURCE_DATE_EPOCH) +%m/%d/%Y;\ + done ) >> $@ +endef + define Device/Default PROFILES = Default KERNEL := kernel-bin | append-dtb | gzip | uImage gzip @@ -71,6 +79,7 @@ define Device/zyxel_gs1900-10hp DEVICE_VENDOR := ZyXEL DEVICE_MODEL := GS1900-10HP UIMAGE_MAGIC := 0x83800000 + KERNEL_INITRAMFS := kernel-bin | append-dtb | gzip | zyxel-vers AAZI | uImage gzip endef TARGET_DEVICES += zyxel_gs1900-10hp @@ -82,6 +91,7 @@ define Device/zyxel_gs1900-8hp-v1 DEVICE_VARIANT := v1 DEVICE_PACKAGES += lua-rs232 UIMAGE_MAGIC := 0x83800000 + KERNEL_INITRAMFS := kernel-bin | append-dtb | gzip | zyxel-vers AAHI | uImage gzip endef TARGET_DEVICES += zyxel_gs1900-8hp-v1 @@ -93,6 +103,7 @@ define Device/zyxel_gs1900-8hp-v2 DEVICE_VARIANT := v2 DEVICE_PACKAGES += lua-rs232 UIMAGE_MAGIC := 0x83800000 + KERNEL_INITRAMFS := kernel-bin | append-dtb | gzip | zyxel-vers AAHI | uImage gzip endef TARGET_DEVICES += zyxel_gs1900-8hp-v2