From 265f402fbdd8444835b43954bf27a83bc9369b91 Mon Sep 17 00:00:00 2001 From: Sieng Piaw Liew Date: Wed, 15 Jun 2022 12:17:24 +0800 Subject: [PATCH 01/10] ath79: ag71xx: reuse skbuff_head with napi skb api napi_build_skb() reuses NAPI skbuff_head cache in order to save some cycles on freeing/allocating skbuff_heads on every new Rx or completed Tx. Use napi_consume_skb() to feed the cache with skbuff_heads of completed Tx so it's never empty. Signed-off-by: Sieng Piaw Liew [ fixed commit title ] Signed-off-by: Christian Marangi --- .../files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c b/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c index 2fc18d5979..d6e8dd20c8 100644 --- a/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c +++ b/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c @@ -1278,7 +1278,7 @@ static int ag71xx_tx_packets(struct ag71xx *ag, bool flush) if (!skb) continue; - dev_kfree_skb_any(skb); + napi_consume_skb(skb, !flush); ring->buf[i].skb = NULL; bytes_compl += ring->buf[i].len; @@ -1352,7 +1352,11 @@ static int ag71xx_rx_packets(struct ag71xx *ag, int limit) dev->stats.rx_packets++; dev->stats.rx_bytes += pktlen; +#if LINUX_VERSION_CODE < KERNEL_VERSION(5,12,0) skb = build_skb(ring->buf[i].rx_buf, ag71xx_buffer_size(ag)); +#else + skb = napi_build_skb(ring->buf[i].rx_buf, ag71xx_buffer_size(ag)); +#endif if (!skb) { skb_free_frag(ring->buf[i].rx_buf); goto next; From 6ad1bea2a60342c4e7742b1acee9cf2c568422da Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Tue, 28 Jun 2022 01:21:44 +0100 Subject: [PATCH 02/10] xdp-tools: add package xdp-tools - Library and utilities for use with the eXpress Data Path: Fast Programmable Packet Processing in the Operating System Kernel * libxdp: library for attaching XDP programs and using AF_XDP sockets * xdp-filter: a simple XDP-powered packet filter * xdp-loader: an XDP program loader * xdpdump: tool for capturing packets at the XDP layer Thanks to Nick @PolynomialDivision Hainke for testing and fixing! Signed-off-by: Daniel Golle --- package/network/utils/xdp-tools/Makefile | 131 +++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 package/network/utils/xdp-tools/Makefile diff --git a/package/network/utils/xdp-tools/Makefile b/package/network/utils/xdp-tools/Makefile new file mode 100644 index 0000000000..3b93a13163 --- /dev/null +++ b/package/network/utils/xdp-tools/Makefile @@ -0,0 +1,131 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=xdp-tools +PKG_RELEASE:=$(AUTORELEASE) +PKG_VERSION:=1.2.5 +PKG_HASH:=140c9bdffe4f2b15bc2973b5f975d0fa5cc011f5a699c7bcdcb698b724b97d4d + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_SOURCE_URL:=https://codeload.github.com/xdp-project/xdp-tools/tar.gz/v$(PKG_VERSION)? +PKG_ABI_VERSION:=$(call abi_version_str,$(PKG_VERSION)) + +PKG_MAINTAINER:=Daniel Golle + +PKG_BUILD_DEPENDS:=bpf-headers + +include $(INCLUDE_DIR)/package.mk +include $(INCLUDE_DIR)/bpf.mk + +PKG_BUILD_PARALLEL:=1 +PKG_INSTALL:=1 + +define Package/libxdp + SECTION:=libs + CATEGORY:=Libraries + TITLE:=libxdp - Library for use with XDP + LICENSE:=LGPL-2.1 OR BSD-2-Clause + ABI_VERSION:=$(PKG_ABI_VERSION) + URL:=https://github.com/xdp-project/xdp-tools/ + DEPENDS:=+libbpf $(BPF_DEPENDS) +endef + +define Package/libxdp/description +libxdp - library for attaching XDP programs and using AF_XDP sockets +endef + +define Package/xdp-tools/Default + SECTION:=net + CATEGORY:=Network + LICENSE:=GPL-2.0-only + URL:=https://github.com/xdp-project/xdp-tools/ + DEPENDS:=+libxdp +endef + +define Package/xdp-filter +$(call Package/xdp-tools/Default) + TITLE:=xdp-filter - a simple XDP-powered packet filter +endef + +define Package/xdp-filter/description +xdp-filter is a packet filtering utility powered by XDP. It is deliberately +simple and so does not have the same matching capabilities as, e.g., +netfilter. Instead, thanks to XDP, it can achieve very high drop rates: +tens of millions of packets per second on a single CPU core. +endef + + +define Package/xdp-loader +$(call Package/xdp-tools/Default) + TITLE:=xdp-loader - an XDP program loader +endef + +define Package/xdp-loader/description +xdp-loader is a simple loader for XDP programs with support for attaching +multiple programs to the same interface. To achieve this it exposes the same +load and unload semantics exposed by the libxdp library. +endef + +define Package/xdpdump +$(call Package/xdp-tools/Default) + TITLE:=xdpdump - tool for capturing packets at the XDP layer + DEPENDS+=+libpcap +endef + +define Package/xdpdump/description +xdpdump - a simple tcpdump like tool for capturing packets at the XDP layer +endef + +CONFIGURE_VARS += \ + FORCE_SYSTEM_LIBBPF=1 \ + CC="$(TARGET_CC)" \ + CFLAGS="$(TARGET_CFLAGS)" \ + LDFLAGS="$(TARGET_LDFLAGS)" \ + CLANG="$(CLANG)" \ + BPF_CFLAGS="$(BPF_CFLAGS)" \ + BPF_TARGET="$(BPF_TARGET)" \ + LLC="$(LLVM_LLC)" + +MAKE_VARS += \ + PREFIX=/usr \ + RUNDIR=/tmp/run + +define Build/InstallDev + $(INSTALL_DIR) $(1)/usr/include/xdp + $(CP) $(PKG_INSTALL_DIR)/usr/include/xdp/*.h $(1)/usr/include/xdp/ + $(INSTALL_DIR) $(1)/usr/lib/bpf + $(CP) $(PKG_INSTALL_DIR)/usr/lib/libxdp.{a,so*} $(1)/usr/lib/ + $(CP) $(PKG_INSTALL_DIR)/usr/lib/bpf/*.o $(1)/usr/lib/bpf + $(INSTALL_DIR) $(1)/usr/lib/pkgconfig + $(CP) $(PKG_INSTALL_DIR)/usr/lib/pkgconfig/libxdp.pc \ + $(1)/usr/lib/pkgconfig/ + $(SED) 's,/usr/include,$$$${prefix}/include,g' \ + $(1)/usr/lib/pkgconfig/libxdp.pc + $(SED) 's,/usr/lib,$$$${exec_prefix}/lib,g' \ + $(1)/usr/lib/pkgconfig/libxdp.pc +endef + +define Package/xdp-filter/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/xdp-filter $(1)/usr/sbin +endef + +define Package/xdp-loader/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/xdp-loader $(1)/usr/sbin +endef + +define Package/xdpdump/install + $(INSTALL_DIR) $(1)/usr/sbin + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/xdpdump $(1)/usr/sbin +endef + +define Package/libxdp/install + $(INSTALL_DIR) $(1)/usr/lib/bpf + $(CP) $(PKG_INSTALL_DIR)/usr/lib/libxdp.so.* $(1)/usr/lib/ + $(CP) $(PKG_INSTALL_DIR)/usr/lib/bpf/*.o $(1)/usr/lib/bpf +endef + +$(eval $(call BuildPackage,libxdp)) +$(eval $(call BuildPackage,xdp-filter)) +$(eval $(call BuildPackage,xdp-loader)) +$(eval $(call BuildPackage,xdpdump)) From 1d3b57dbeeae70ab3a8f71d3bdb6fd41a00e1d22 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 4 Jul 2022 18:33:13 +0100 Subject: [PATCH 03/10] mvebu: cortexa72: fix ImageBuilder for IEI Puzzle devices The line trying to generate the standard sdcard.img.gz fails due to boot.scr not being generated. Remove the line in order to use the default sdcard.img.gz which is exactly the same but includes generating the boot.scr file. Signed-off-by: Daniel Golle --- target/linux/mvebu/image/cortexa72.mk | 2 -- 1 file changed, 2 deletions(-) diff --git a/target/linux/mvebu/image/cortexa72.mk b/target/linux/mvebu/image/cortexa72.mk index 84ce0cda9a..47d958b2fd 100644 --- a/target/linux/mvebu/image/cortexa72.mk +++ b/target/linux/mvebu/image/cortexa72.mk @@ -68,7 +68,6 @@ define Device/iei_puzzle-m901 DEVICE_VENDOR := iEi DEVICE_MODEL := Puzzle-M901 SOC := cn9131 - IMAGE/sdcard.img.gz := boot-img-ext4 | sdcard-img-ext4 | gzip | append-metadata endef TARGET_DEVICES += iei_puzzle-m901 @@ -77,6 +76,5 @@ define Device/iei_puzzle-m902 DEVICE_VENDOR := iEi DEVICE_MODEL := Puzzle-M902 SOC := cn9132 - IMAGE/sdcard.img.gz := boot-img-ext4 | sdcard-img-ext4 | gzip | append-metadata endef TARGET_DEVICES += iei_puzzle-m902 From f58e562b07803192d029a6be8c8c372e1ed11c68 Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 4 Jul 2022 18:42:20 +0100 Subject: [PATCH 04/10] mediatek: mt7622: fix white dome LED of UniFi 6 LR The recent differentiation between v1 and v2 of the UniFi 6 LR added support for the v2 version which has GPIO-controlled LEDs instead of using an additional microcontroller to drive an RGB led. The polarity of the white LED, however, was inverted and the default states didn't make a lot of sense after all. Fix that. Signed-off-by: Daniel Golle --- target/linux/mediatek/dts/mt7622-ubnt-unifi-6-lr-v2.dtsi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/target/linux/mediatek/dts/mt7622-ubnt-unifi-6-lr-v2.dtsi b/target/linux/mediatek/dts/mt7622-ubnt-unifi-6-lr-v2.dtsi index 3e9cea7285..4d278805d4 100644 --- a/target/linux/mediatek/dts/mt7622-ubnt-unifi-6-lr-v2.dtsi +++ b/target/linux/mediatek/dts/mt7622-ubnt-unifi-6-lr-v2.dtsi @@ -13,13 +13,11 @@ led_white: dome_white { label = "white:dome"; - linux,default-trigger = "default-on"; - gpios = <&pio 0x43 GPIO_ACTIVE_HIGH>; + gpios = <&pio 0x43 GPIO_ACTIVE_LOW>; }; led_blue: dome_blue { label = "blue:dome"; - default-state = "off"; gpios = <&pio 0x44 GPIO_ACTIVE_HIGH>; }; }; From a0c5b03e02528b938f1c6d411a582b67b7e9fe7b Mon Sep 17 00:00:00 2001 From: Nick Hainke Date: Mon, 4 Jul 2022 09:52:43 +0200 Subject: [PATCH 05/10] f2fs-tools: import patch to fix compilation Disable lz4 and lzo2 manually. Fixes errors in the form of: Package f2fsck is missing dependencies for the following libraries: liblz4.so.1 liblzo2.so.2 Fixes: 8b9e80616011 ("f2fs-tools: update to 1.15.0") Acked-by: Thomas Huehn Signed-off-by: Nick Hainke --- package/utils/f2fs-tools/Makefile | 4 +- ...1-configure.ac-fix-cross-compilation.patch | 80 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 package/utils/f2fs-tools/patches/101-configure.ac-fix-cross-compilation.patch diff --git a/package/utils/f2fs-tools/Makefile b/package/utils/f2fs-tools/Makefile index 8f53516d34..60f4b317c7 100644 --- a/package/utils/f2fs-tools/Makefile +++ b/package/utils/f2fs-tools/Makefile @@ -99,7 +99,9 @@ endef CONFIGURE_ARGS += \ --disable-static \ - --without-blkid + --without-blkid \ + --without-lzo2 \ + --without-lz4 ifneq ($(BUILD_VARIANT),selinux) CONFIGURE_ARGS += --without-selinux diff --git a/package/utils/f2fs-tools/patches/101-configure.ac-fix-cross-compilation.patch b/package/utils/f2fs-tools/patches/101-configure.ac-fix-cross-compilation.patch new file mode 100644 index 0000000000..b9edd6634b --- /dev/null +++ b/package/utils/f2fs-tools/patches/101-configure.ac-fix-cross-compilation.patch @@ -0,0 +1,80 @@ +From 821a1d3fcce31c234512a8f4dc4fc97dfbd7ae32 Mon Sep 17 00:00:00 2001 +From: Nick Hainke +Date: Mon, 4 Jul 2022 09:46:10 +0200 +Subject: [PATCH] configure.ac: fix cross compilation + +AC_CHECK_LIB seems to not work correctly with OpenWrt. Add possibility +to disable lz4 and lzo2 manually. + +Fixes errors in the form of: + Package f2fsck is missing dependencies for the following libraries: + liblz4.so.1 + liblzo2.so.2 + +Signed-off-by: Nick Hainke +--- + configure.ac | 44 ++++++++++++++++++++++++++++++++++---------- + 1 file changed, 34 insertions(+), 10 deletions(-) + +--- a/configure.ac ++++ b/configure.ac +@@ -50,6 +50,18 @@ AC_ARG_WITH([blkid], + [], + [with_blkid=check]) + ++AC_ARG_WITH([lzo2], ++ [AS_HELP_STRING([--without-lzo2], ++ [Ignore presence of liblzo2 and disable lzo2 support])], ++ [], ++ [with_lzo2=check]) ++ ++AC_ARG_WITH([lz4], ++ [AS_HELP_STRING([--without-lz4], ++ [Ignore presence of liblz4 and disable lz4 support])], ++ [], ++ [with_lz4=check]) ++ + # Checks for programs. + AC_PROG_CC + AM_PROG_AR +@@ -71,17 +83,29 @@ AS_IF([test "x$with_blkid" != xno], + fi + ], -lblkid)]) + +-AC_CHECK_LIB([lzo2], [main], +- [AC_SUBST([liblzo2_LIBS], ["-llzo2"]) +- AC_DEFINE([HAVE_LIBLZO2], [1], +- [Define if you have liblzo2]) +- ], [], []) +- +-AC_CHECK_LIB([lz4], [main], +- [AC_SUBST([liblz4_LIBS], ["-llz4"]) +- AC_DEFINE([HAVE_LIBLZ4], [1], +- [Define if you have liblz4]) +- ], [], []) ++AS_IF([test "x$with_lzo2" != xno], ++ [AC_CHECK_LIB([lzo2], [main], ++ [AC_SUBST([liblzo2_LIBS], ["-llzo2"]) ++ AC_DEFINE([HAVE_LIBLZO2], [1], ++ [Define if you have liblzo2]) ++ ], ++ [if test "x$with_lzo2" != xcheck; then ++ AC_MSG_FAILURE( ++ [--with-lzo2 was given, but test for lzo2 failed]) ++ fi ++ ], -llzo2)]) ++ ++AS_IF([test "x$with_lz4" != xno], ++ [AC_CHECK_LIB([lz4], [main], ++ [AC_SUBST([liblz4_LIBS], ["-llz4"]) ++ AC_DEFINE([HAVE_LIBLZ4], [1], ++ [Define if you have liblz4]) ++ ], ++ [if test "x$with_lz4" != xcheck; then ++ AC_MSG_FAILURE( ++ [--with-lz4 was given, but test for lz4 failed]) ++ fi ++ ], -llz4)]) + + AS_IF([test "x$with_selinux" != xno], + [AC_CHECK_LIB([selinux], [getcon], From 341121edd49428acb992ce34b27e51454ca904cf Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Mon, 4 Jul 2022 00:56:19 -0700 Subject: [PATCH 06/10] libjson-c: disable libbsd libjson-c is happy to pick up libbsd both on the host and target. Reproducible with make package/libbsd/compile;make package/libjson-c/compile Also fixes host compilation on Arch Linux for a similar reason. Undefined reference to arc4random. Fixes: f3a198697f60 ("libjson-c: update to 0.16") Acked-by: Thomas Huehn thomas.huehn@hs-nordhausen.de Acked-by: Nick Hainke vincent@systemli.org Signed-off-by: Rosen Penev --- package/libs/libjson-c/Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/package/libs/libjson-c/Makefile b/package/libs/libjson-c/Makefile index 2b90c27a4a..2c312f200e 100644 --- a/package/libs/libjson-c/Makefile +++ b/package/libs/libjson-c/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=json-c PKG_VERSION:=0.16 -PKG_RELEASE:=1 +PKG_RELEASE:=2 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-nodoc.tar.gz PKG_SOURCE_URL:=https://s3.amazonaws.com/json-c_releases/releases/ @@ -27,8 +27,12 @@ include $(INCLUDE_DIR)/host-build.mk include $(INCLUDE_DIR)/cmake.mk CMAKE_HOST_OPTIONS += \ + -DDISABLE_EXTRA_LIBS=TRUE \ -DBUILD_SHARED_LIBS=FALSE +CMAKE_OPTIONS += \ + -DDISABLE_EXTRA_LIBS=TRUE + define Package/libjson-c SECTION:=libs CATEGORY:=Libraries From eb7d2abbf06f0a3fe700df5dc6b57ee90016f1f1 Mon Sep 17 00:00:00 2001 From: Andre Heider Date: Thu, 23 Jun 2022 09:08:07 +0200 Subject: [PATCH 07/10] openssl: bump to 1.1.1p MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes between 1.1.1o and 1.1.1p [21 Jun 2022] *) In addition to the c_rehash shell command injection identified in CVE-2022-1292, further bugs where the c_rehash script does not properly sanitise shell metacharacters to prevent command injection have been fixed. When the CVE-2022-1292 was fixed it was not discovered that there are other places in the script where the file names of certificates being hashed were possibly passed to a command executed through the shell. This script is distributed by some operating systems in a manner where it is automatically executed. On such operating systems, an attacker could execute arbitrary commands with the privileges of the script. Use of the c_rehash script is considered obsolete and should be replaced by the OpenSSL rehash command line tool. (CVE-2022-2068) [Daniel Fiala, Tomáš Mráz] *) When OpenSSL TLS client is connecting without any supported elliptic curves and TLS-1.3 protocol is disabled the connection will no longer fail if a ciphersuite that does not use a key exchange based on elliptic curves can be negotiated. [Tomáš Mráz] Signed-off-by: Andre Heider --- package/libs/openssl/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/libs/openssl/Makefile b/package/libs/openssl/Makefile index b496f2f9f2..ed618568a4 100644 --- a/package/libs/openssl/Makefile +++ b/package/libs/openssl/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=openssl PKG_BASE:=1.1.1 -PKG_BUGFIX:=o +PKG_BUGFIX:=p PKG_VERSION:=$(PKG_BASE)$(PKG_BUGFIX) PKG_RELEASE:=$(AUTORELEASE) PKG_USE_MIPS16:=0 @@ -25,7 +25,7 @@ PKG_SOURCE_URL:= \ ftp://ftp.pca.dfn.de/pub/tools/net/openssl/source/ \ ftp://ftp.pca.dfn.de/pub/tools/net/openssl/source/old/$(PKG_BASE)/ -PKG_HASH:=9384a2b0570dd80358841464677115df785edb941c71211f75076d72fe6b438f +PKG_HASH:=bf61b62aaa66c7c7639942a94de4c9ae8280c08f17d4eac2e44644d9fc8ace6f PKG_LICENSE:=OpenSSL PKG_LICENSE_FILES:=LICENSE From f9e840b65700e1cdff6d066d39c163bac936d046 Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Tue, 5 Jul 2022 08:46:21 +0200 Subject: [PATCH 08/10] scripts: add CAMEO tag generator This script inserts CAMEO tags into an uImage to make U-Boot of DGS-1210 switches happy. Signed-off-by: Markus Stockhausen Suggested-by: Sander Vanheule # Mutual checksum algorithm [commit title prefix, trailing whitespace, OpenWrt capitalisation, move CRC calculation comment, use UIMAGE_NAME_*, remove parentheses for return, use f-string instead of str()] Signed-off-by: Sander Vanheule --- scripts/cameo-tag.py | 117 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100755 scripts/cameo-tag.py diff --git a/scripts/cameo-tag.py b/scripts/cameo-tag.py new file mode 100755 index 0000000000..643dd387e8 --- /dev/null +++ b/scripts/cameo-tag.py @@ -0,0 +1,117 @@ +#!/usr/bin/python3 +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Copyright (C) 2022 OpenWrt.org +# +# ./cameo-tag.py +# +# CAMEO tag generator used for the D-Link DGS-1210 switches. Their U-Boot +# loader checks for the string CAMEOTAG and a checksum in the kernel and +# rootfs partitions. If not found it complains about the boot image. +# Nevertheless it will boot if the tags are available in the secondary +# boot partitions. If some day we want to overwrite the original vendor +# partition we must have the tags in place. To solve this we insert the +# tag two times into the kernel image. +# +# To understand what we do here it is helpful to explain how the original +# CAMEO tag generation/checking works. The firmware consists of two parts. +# A kernel uImage (<1.5MB) and a rootfs image (<12MB) that are written to +# their respective mtd partitions. The default generator simply checksums +# both parts and appends 16 bytes [<0001>] to each part. +# The checksum is only an addition of all preceding bytes (b0+b1+b2+...). +# A tag does not interfere with any data in the images itself. During boot +# the loader will scan all primary/secondary partitions (2*kernel, 2*rootfs) +# until it finds the CAMEO tag. If checksums match everything is fine. +# If all 4 fail we are lost. Luckily the loader does not care about where +# the tags are located and ignores any data beyond a tag. +# +# The OpenWrt image consists of a kernel (>1.5MB) and a rootfs. There is +# no chance to add CAMEO tags at the default locations, since the kernel spans +# both the original kernel partition and the start of the rootfs partition. +# This would leave the kernel partition without a tag. So we must find suitable +# space. +# +# Location for original kernel partition is at the end of the uImage header. +# We will reuse the last bytes of the IH_NAME field. This is the tricky part +# because we have the header CRC and the CAMEO checksum that must match the +# whole header. uImage header CRC checksums all data except the CRC itself. The +# for CAMEO checksum in turn, checksums all preceding data except itself. +# Changing one of both results in a change of the other, but data trailing the +# CAMEO checksum only influences the CRC. +# +# Location for original rootfs partition is very simple. It is behind the +# OpenWrt compressed kernel image file that spans into the rootfs. So +# the tag will be written somewhere to the following rootfs partition and +# can be found by U-Boot. The CAMEO checksum calculation must start at the +# offset of the original rootfs partition and includes the "second" half of the +# "split" kernel uImage. + +import argparse +import os +import zlib + +READ_UNTIL_EOF = -1 +UIMAGE_HEADER_SIZE = 64 +UIMAGE_CRC_SLICE = 4 +UIMAGE_CRC_END = 8 +UIMAGE_NAME_OFF = 32 +UIMAGE_NAME_END = 56 +UIMAGE_SUM_OFF = 56 +UIMAGE_SUM_END = 60 +UIMAGE_INV_OFF = 60 +UIMAGE_INV_END = 64 +CAMEO_TAG = bytes([0x43, 0x41, 0x4d, 0x45, 0x4f, 0x54, 0x41, 0x47, 0x00, 0x00, 0x00, 0x01]) +IMAGE_NAME = bytes([0x4f, 0x70, 0x65, 0x6e, 0x57, 0x72, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00]) +CRC_00 = bytes([0x00] * 4) +CRC_FF = bytes([0xff] * 4) + +def read_buffer(offset, count): + args.uimage_file.seek(offset) + return bytearray(args.uimage_file.read(count)) + +def write_buffer(whence, buf): + args.uimage_file.seek(0, whence) + args.uimage_file.write(buf) + +def cameosum(buf): + return (sum(buf) & 0xffffffff).to_bytes(4, 'big') + +def invertcrc(buf): + return (zlib.crc32(buf) ^ 0xffffffff).to_bytes(4, 'little') + +def checksum_header(buf): + # To efficently get a combination, we will make use of the following fact: + # crc32(data + littleendian(crc32(data) ^ 0xffffffff)) = 0xffffffff + # + # After manipulation the uImage header looks like this: + # [......<000000><0001>] + buf[UIMAGE_NAME_OFF:UIMAGE_NAME_END] = IMAGE_NAME + CAMEO_TAG + buf[UIMAGE_CRC_OFF:UIMAGE_CRC_END] = CRC_FF + buf[UIMAGE_SUM_OFF:UIMAGE_SUM_END] = cameosum(buf[0:UIMAGE_NAME_END]) + buf[UIMAGE_CRC_OFF:UIMAGE_CRC_END] = CRC_00 + buf[UIMAGE_INV_OFF:UIMAGE_INV_END] = invertcrc(buf[0:UIMAGE_SUM_END]) + buf[UIMAGE_CRC_OFF:UIMAGE_CRC_END] = CRC_FF + return buf + +parser = argparse.ArgumentParser(description='Insert CAMEO firmware tags.') +parser.add_argument('uimage_file', type=argparse.FileType('r+b')) +parser.add_argument('rootfs_start', type=int) +args = parser.parse_args() + +args.uimage_file.seek(0, os.SEEK_END) +if args.uimage_file.tell() <= args.rootfs_start: + raise ValueError(f"uImage must be larger than {args.rootfs_start} bytes") + +# tag for the uImage Header of 64 bytes inside the kernel +# partition. Read and mangle it so it contains a valid CAMEO tag +# and checksum that matches perfectly to the uImage header CRC. + +buf = checksum_header(read_buffer(0, UIMAGE_HEADER_SIZE)) +write_buffer(os.SEEK_SET, buf) + +# tag for the second part of the kernel that resides in the +# vendor rootfs partition. For this we will add the CAMEO tag +# and the checksum to the end of the image. + +buf = read_buffer(args.rootfs_start, READ_UNTIL_EOF) +write_buffer(os.SEEK_END, CAMEO_TAG + cameosum(buf + CAMEO_TAG)) From e763c4c89fc5569d7264ff60837eb4aff69a0bfb Mon Sep 17 00:00:00 2001 From: Markus Stockhausen Date: Tue, 5 Jul 2022 08:46:59 +0200 Subject: [PATCH 09/10] realtek: build DGS-1210 images with CAMEO tag From now on we will insert CAMEO tags into sysupgrade images for DGS-1210 devices. This will make the "OS:...FAILED" and "FS:...FAILED" messages go away. Signed-off-by: Markus Stockhausen --- target/linux/realtek/image/Makefile | 4 ++++ target/linux/realtek/image/rtl838x.mk | 1 + 2 files changed, 5 insertions(+) diff --git a/target/linux/realtek/image/Makefile b/target/linux/realtek/image/Makefile index b54a1f0a8d..3a1ba2f60e 100644 --- a/target/linux/realtek/image/Makefile +++ b/target/linux/realtek/image/Makefile @@ -17,6 +17,10 @@ define Build/zyxel-vers done ) >> $@ endef +define Build/dlink-cameo + $(SCRIPT_DIR)/cameo-tag.py $@ $(DLINK_KERNEL_PART_SIZE) +endef + define Build/dlink-headers dd if=$@ bs=$(DLINK_KERNEL_PART_SIZE) count=1 of=$@.kernel_part; \ dd if=$@ bs=$(DLINK_KERNEL_PART_SIZE) skip=1 of=$@.rootfs_part; \ diff --git a/target/linux/realtek/image/rtl838x.mk b/target/linux/realtek/image/rtl838x.mk index c01acd10bc..dc18182110 100644 --- a/target/linux/realtek/image/rtl838x.mk +++ b/target/linux/realtek/image/rtl838x.mk @@ -16,6 +16,7 @@ define Device/d-link_dgs-1210 IMAGE_SIZE := 13824k DEVICE_VENDOR := D-Link DLINK_KERNEL_PART_SIZE := 1572864 + KERNEL := kernel-bin | append-dtb | gzip | uImage gzip | dlink-cameo endef define Device/d-link_dgs-1210-10p From ebfe66e494e57f4b421f1190d6bff1d361db1b3d Mon Sep 17 00:00:00 2001 From: Sander Vanheule Date: Tue, 5 Jul 2022 10:16:08 +0200 Subject: [PATCH 10/10] scripts: fix CAMEO tag generator What should have been only cosmetic changes, ended up in breaking the script. Rename UIMAGE_CRC_SLICE back to (the original) UIMAGE_CRC_OFF. Fixes issue #10204 "cameo-tag.py broken" Reported-by: Markus Stockhausen Fixes: f9e840b65700 ("scripts: add CAMEO tag generator") Signed-off-by: Sander Vanheule --- scripts/cameo-tag.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cameo-tag.py b/scripts/cameo-tag.py index 643dd387e8..becd69f8e7 100755 --- a/scripts/cameo-tag.py +++ b/scripts/cameo-tag.py @@ -52,7 +52,7 @@ import zlib READ_UNTIL_EOF = -1 UIMAGE_HEADER_SIZE = 64 -UIMAGE_CRC_SLICE = 4 +UIMAGE_CRC_OFF = 4 UIMAGE_CRC_END = 8 UIMAGE_NAME_OFF = 32 UIMAGE_NAME_END = 56