From 45b3f2aa0f57c7ca694317aca462d6ed1e183a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Fri, 4 Mar 2022 09:39:04 +0100 Subject: [PATCH 1/3] uboot-bcm4908: add package with BCM4908 U-Boot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New BCM4908 devices come with U-Boot instead of CFE. Firmwares for such devices has to include U-Boot. Signed-off-by: Rafał Miłecki (cherry picked from commit 0d45e1ea96ef29649f080c54f99fb1c80482421b) --- package/boot/uboot-bcm4908/Makefile | 48 ++++++++++++++++ ...ow-to-complete-build-even-with-ad-ho.patch | 40 ++++++++++++++ ...tools-fix-mkimage-static-compilation.patch | 24 ++++++++ ...00-configs-bcm94908-unset-CONFIG_SPL.patch | 38 +++++++++++++ ...rt-for-ATF-when-compiling-U-Boot-wit.patch | 55 +++++++++++++++++++ 5 files changed, 205 insertions(+) create mode 100644 package/boot/uboot-bcm4908/Makefile create mode 100644 package/boot/uboot-bcm4908/patches/100-check-config-allow-to-complete-build-even-with-ad-ho.patch create mode 100644 package/boot/uboot-bcm4908/patches/101-tools-fix-mkimage-static-compilation.patch create mode 100644 package/boot/uboot-bcm4908/patches/200-configs-bcm94908-unset-CONFIG_SPL.patch create mode 100644 package/boot/uboot-bcm4908/patches/201-Assume-TPL-support-for-ATF-when-compiling-U-Boot-wit.patch diff --git a/package/boot/uboot-bcm4908/Makefile b/package/boot/uboot-bcm4908/Makefile new file mode 100644 index 0000000000..489b4d69bf --- /dev/null +++ b/package/boot/uboot-bcm4908/Makefile @@ -0,0 +1,48 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +include $(TOPDIR)/rules.mk +include $(INCLUDE_DIR)/kernel.mk + +PKG_RELEASE:=$(AUTORELEASE) + +PKG_SOURCE_PROTO:=git +PKG_SOURCE_URL:=https://git.openwrt.org/project/bcm63xx/u-boot.git +PKG_SOURCE_DATE:=2022-03-03 +PKG_SOURCE_VERSION:=92e9eca819c9c898d9d2010e1a217726c42c8c47 +PKG_MIRROR_HASH:=11c37fe4c18d55e799153600d1cfd8ee9ca7da8326d0024c1d825f4a327c5f0d + +include $(INCLUDE_DIR)/u-boot.mk +include $(INCLUDE_DIR)/package.mk + +define U-Boot/Default + BUILD_TARGET:=bcm4908 + UBOOT_IMAGE:=u-boot-nodtb.bin + DEFAULT:=y +endef + +define U-Boot/bcm4908 + NAME:=Broadcom's BCM4908 + UBOOT_CONFIG:=bcm94908 +endef + +UBOOT_TARGETS := \ + bcm4908 + +define Build/Prepare + $(call Build/Prepare/Default) + mkdir -p $(PKG_BUILD_DIR)/include/generated/ + ( cd $(PKG_BUILD_DIR)/board/broadcom/bcmbca/httpd/html/ && \ + xxd -i index.html > ../../../../../include/generated/index.h && \ + xxd -i flashing.html > ../../../../../include/generated/flashing.h && \ + xxd -i fail.html > ../../../../../include/generated/fail.h && \ + xxd -i 404.html > ../../../../../include/generated/404.h ) +endef + +define Build/InstallDev + $(INSTALL_DIR) $(STAGING_DIR_IMAGE)/u-boot + $(INSTALL_BIN) $(PKG_BUILD_DIR)/$(UBOOT_IMAGE) $(STAGING_DIR_IMAGE)/u-boot/ + $(INSTALL_BIN) $(PKG_BUILD_DIR)/u-boot.dtb $(STAGING_DIR_IMAGE)/u-boot/ + $(INSTALL_BIN) $(PKG_BUILD_DIR)/arch/arm/dts/*.dtb $(STAGING_DIR_IMAGE)/u-boot/ +endef + +$(eval $(call BuildPackage/U-Boot)) diff --git a/package/boot/uboot-bcm4908/patches/100-check-config-allow-to-complete-build-even-with-ad-ho.patch b/package/boot/uboot-bcm4908/patches/100-check-config-allow-to-complete-build-even-with-ad-ho.patch new file mode 100644 index 0000000000..44aa4c17e6 --- /dev/null +++ b/package/boot/uboot-bcm4908/patches/100-check-config-allow-to-complete-build-even-with-ad-ho.patch @@ -0,0 +1,40 @@ +From: Masahiro Yamada +Date: Mon, 26 Sep 2016 13:05:02 +0900 +Subject: [PATCH] check-config: allow to complete build even with ad-hoc CONFIG + options + +Currently, the check-config.sh terminates the build when unknown +ad-hoc options are detected. I think it is too much because we may +want to patch config headers locally in a build/deployment project. + +So, let's relax check-config.sh to just warn even if it detects +options that are not in the whitelist. Instead, this check can be +done at the end of build, along with other checks. It will catch +more attention. + +Even with this change, the Buildman tool catches new warnings, +so Tom can give NACK to new ad-hoc options. + +Signed-off-by: Masahiro Yamada +--- + scripts/check-config.sh | 3 +-- + 1 file changed, 1 insertion(+), 2 deletions(-) + +--- a/scripts/check-config.sh ++++ b/scripts/check-config.sh +@@ -50,14 +50,13 @@ cat `find ${srctree} -name "Kconfig*"` |sed -n \ + |sort |uniq > ${ok} + comm -23 ${suspects} ${ok} >${new_adhoc} + if [ -s ${new_adhoc} ]; then +- echo >&2 "Error: You must add new CONFIG options using Kconfig" ++ echo >&2 "Warning: You must add new CONFIG options using Kconfig" + echo >&2 "The following new ad-hoc CONFIG options were detected:" + cat >&2 ${new_adhoc} + echo >&2 + echo >&2 "Please add these via Kconfig instead. Find a suitable Kconfig" + echo >&2 "file and add a 'config' or 'menuconfig' option." + # Don't delete the temporary files in case they are useful +- exit 1 + else + rm ${suspects} ${ok} ${new_adhoc} + fi diff --git a/package/boot/uboot-bcm4908/patches/101-tools-fix-mkimage-static-compilation.patch b/package/boot/uboot-bcm4908/patches/101-tools-fix-mkimage-static-compilation.patch new file mode 100644 index 0000000000..9b50071168 --- /dev/null +++ b/package/boot/uboot-bcm4908/patches/101-tools-fix-mkimage-static-compilation.patch @@ -0,0 +1,24 @@ +From 8efe417aa9de654425cc01d0fc93be355a3f648d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Wed, 13 Oct 2021 11:04:45 +0200 +Subject: [PATCH] tools: fix mkimage static compilation +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Rafał Miłecki +--- + tools/Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/tools/Makefile ++++ b/tools/Makefile +@@ -157,7 +157,7 @@ ifneq ($(CONFIG_MX23)$(CONFIG_MX28)$(CON + HOSTCFLAGS_kwbimage.o += \ + $(shell pkg-config --cflags libssl libcrypto 2> /dev/null || echo "") + HOSTLOADLIBES_mkimage += \ +- $(shell pkg-config --libs libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto") ++ $(shell pkg-config --libs --static libssl libcrypto 2> /dev/null || echo "-lssl -lcrypto -lpthread") + + # OS X deprecate openssl in favour of CommonCrypto, supress deprecation + # warnings on those systems diff --git a/package/boot/uboot-bcm4908/patches/200-configs-bcm94908-unset-CONFIG_SPL.patch b/package/boot/uboot-bcm4908/patches/200-configs-bcm94908-unset-CONFIG_SPL.patch new file mode 100644 index 0000000000..26189bc571 --- /dev/null +++ b/package/boot/uboot-bcm4908/patches/200-configs-bcm94908-unset-CONFIG_SPL.patch @@ -0,0 +1,38 @@ +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Fri, 4 Mar 2022 09:21:32 +0100 +Subject: [PATCH] configs: bcm94908: unset CONFIG_SPL +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Compiling SPL is always tricky as it needs to fit limited resources. +Fortunately in most cases there is no need to replace SPL or TPL while +flashing a new firmware. + +Compiling SPL for BCM4908 seems to fail with non-Broadcom toolchain: +aarch64-openwrt-linux-musl-ld.bfd: u-boot-spl section `.u_boot_list' will not fit in region `.sram' +aarch64-openwrt-linux-musl-ld.bfd: section .bss VMA [00000000822b9000,00000000822b93ef] overlaps section .u_boot_list VMA [00000000822b8f60,00000000822b9a87] +aarch64-openwrt-linux-musl-ld.bfd: region `.sram' overflowed by 2696 bytes + +It also requires hashtable.h which has to be generated using some +Broadcom's custom perl script that isn't integrated as this point. + +For now just disable SPL and use only last-stage U-Boot that must be +shipped with every firmware. + +Signed-off-by: Rafał Miłecki +--- + configs/bcm94908_defconfig | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/configs/bcm94908_defconfig ++++ b/configs/bcm94908_defconfig +@@ -21,7 +21,7 @@ CONFIG_SPL_SERIAL_SUPPORT=y + CONFIG_TPL_LIBCOMMON_SUPPORT=y + CONFIG_TPL_LIBGENERIC_SUPPORT=y + CONFIG_NR_DRAM_BANKS=1 +-CONFIG_SPL=y ++# CONFIG_SPL is not set + CONFIG_SPL_LIBDISK_SUPPORT=y + CONFIG_ENV_VARS_UBOOT_CONFIG=y + CONFIG_TPL_SYS_MALLOC_F_LEN=0x11000 diff --git a/package/boot/uboot-bcm4908/patches/201-Assume-TPL-support-for-ATF-when-compiling-U-Boot-wit.patch b/package/boot/uboot-bcm4908/patches/201-Assume-TPL-support-for-ATF-when-compiling-U-Boot-wit.patch new file mode 100644 index 0000000000..1e59705ac0 --- /dev/null +++ b/package/boot/uboot-bcm4908/patches/201-Assume-TPL-support-for-ATF-when-compiling-U-Boot-wit.patch @@ -0,0 +1,55 @@ +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Fri, 4 Mar 2022 09:23:34 +0100 +Subject: [PATCH] Assume TPL support for ATF when compiling U-Boot without TPL +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Broadcom's U-Boot behaviour depends on compilation time check whether +TPL was compiled with or without ATF support. There is no proper runtime +check. + +When compiling just U-Boot (without SPL & TPL) there is no way to tell +if it's going to work with TPL with or without ATF support. + +Modify code to blindly assume ATF support in TPL in such cases. It seems +to be always true for Broadcom and we need some assumption as we don't +deal with compiling SPL or TPL. + +Signed-off-by: Rafał Miłecki +--- + arch/arm/mach-bcmbca/bcm4908/cpu.c | 2 +- + board/broadcom/bcmbca/board.c | 4 ++-- + 2 files changed, 3 insertions(+), 3 deletions(-) + +--- a/arch/arm/mach-bcmbca/bcm4908/cpu.c ++++ b/arch/arm/mach-bcmbca/bcm4908/cpu.c +@@ -138,7 +138,7 @@ int get_nr_cpus() + return nr_cpus; + } + +-#if !defined(CONFIG_TPL_ATF) ++#if defined(CONFIG_TPL) && !defined(CONFIG_TPL_ATF) + void boot_secondary_cpu(unsigned long vector) + { + uint32_t cpu, nr_cpus = QUAD_CPUS; +--- a/board/broadcom/bcmbca/board.c ++++ b/board/broadcom/bcmbca/board.c +@@ -103,7 +103,7 @@ void board_spinor_init(void) + + int board_init(void) + { +-#if !defined(CONFIG_TPL_ATF) ++#if defined(CONFIG_TPL) && !defined(CONFIG_TPL_ATF) + unsigned long vector; + #endif + board_sdk_init_e(); +@@ -121,7 +121,7 @@ int board_init(void) + printf("$Uboot: "BUILD_TAG" $\n"); + #endif + +-#if !defined(CONFIG_TPL_ATF) ++#if defined(CONFIG_TPL) && !defined(CONFIG_TPL_ATF) + #if defined(CONFIG_ARM64) + vector = (unsigned long)&_start; + #else From e8a806c49e8b5ee0e6c6c79e9c875d47a9349ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Fri, 4 Mar 2022 09:39:05 +0100 Subject: [PATCH 2/3] bcm4908: include U-Boot in images MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is a step forward in adding support for devices with U-Boot. Signed-off-by: Rafał Miłecki (cherry picked from commit 34fd5e325af5cbcb64696c9b4b1660f22299790f) --- target/linux/bcm4908/image/bootfs-generic.its | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/target/linux/bcm4908/image/bootfs-generic.its b/target/linux/bcm4908/image/bootfs-generic.its index 3cde532d72..bd566d5d22 100644 --- a/target/linux/bcm4908/image/bootfs-generic.its +++ b/target/linux/bcm4908/image/bootfs-generic.its @@ -22,6 +22,20 @@ }; }; + uboot { + description = "U-Boot"; + data = /incbin/("${images_dir}/u-boot/u-boot-nodtb.bin"); + os = "U-Boot"; + arch = "arm64"; + compression = "none"; + load = <0x1000000>; + entry = <0x1000000>; + + hash-1 { + algo = "sha256"; + }; + }; + kernel { description = "Linux kernel"; data = /incbin/("${kernel}"); @@ -37,10 +51,9 @@ }; }; - fdt_linux_RAX220 { + fdt_uboot { description = "dtb"; - data = /incbin/("${dts_dir}/broadcom/bcm4908/bcm4908-netgear-raxe500.dtb"); - arch = "arm64"; + data = /incbin/("${images_dir}/u-boot/u-boot.dtb"); type = "flat_dt"; compression = "none"; @@ -48,9 +61,25 @@ algo = "sha256"; }; }; + + fdt_linux_RAX220 { + description = "dtb"; + data = /incbin/("${dts_dir}/broadcom/bcm4908/bcm4908-netgear-raxe500.dtb"); + arch = "arm64"; + type = "flat_dt"; + compression = "none"; + }; }; configurations { + default = "conf_uboot"; + + conf_uboot { + description = "BRCM 63xxx with uboot"; + fdt = "fdt_uboot"; + loadables = "atf", "uboot"; + }; + conf_lx_RAX220 { description = "BRCM 63xxx linux"; kernel = "kernel"; From f44f8b07b0277d38fafb3d613a303454d3b9faaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Tue, 1 Mar 2022 18:46:27 +0100 Subject: [PATCH 3/3] base-files: call "sync" after initial setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenWrt uses a lot of (b)ash scripts for initial setup. This isn't the best solution as they almost never consider syncing files / data. Still this is what we have and we need to try living with it. Without proper syncing OpenWrt can easily get into an inconsistent state on power cut. It's because: 1. Actual (flash) inode and data writes are not synchronized 2. Data writeback can take up to 30 seconds (dirty_expire_centisecs) 3. ubifs adds extra 5 seconds (dirty_writeback_centisecs) "delay" Some possible cases (examples) for new files: 1. Power cut during 5 seconds after write() can result in all data loss 2. Power cut happening between 5 and 35 seconds after write() can result in empty file (inode flushed after 5 seconds, data flush queued) Above affects e.g. uci-defaults. After executing some migration script it may get deleted (whited out) without generated data getting actually written. Power cut will result in missing data and deleted file. There are three ways of dealing with that: 1. Rewriting all user-space init to proper C with syncs 2. Trying bash hacks (like creating tmp files & moving them) 3. Adding sync and hoping for no power cut during critical section This change introduces the last solution that is the simplest. It reduces time during which things may go wrong from ~35 seconds to probably less than a second. Of course it applies only to IO operations performed before /etc/init.d/boot . It's probably the stage when the most new files get created. All later changes are usually done using smarter C apps (e.g. busybox or uci) that creates tmp files and uses rename() that is expected to be atomic. Signed-off-by: Rafał Miłecki Acked-by: Hauke Mehrtens Acked-by: Sergey Ryazanov (cherry picked from commit 9851d4b6ce6e89d164a04803817625a9041b060a) --- package/base-files/files/etc/init.d/boot | 1 + 1 file changed, 1 insertion(+) diff --git a/package/base-files/files/etc/init.d/boot b/package/base-files/files/etc/init.d/boot index e1c60c1c2f..749d9e9711 100755 --- a/package/base-files/files/etc/init.d/boot +++ b/package/base-files/files/etc/init.d/boot @@ -48,6 +48,7 @@ boot() { /bin/config_generate uci_apply_defaults + sync # temporary hack until configd exists /sbin/reload_config