From: Tomasz Maciej Nowak <tmn...@gmail.com> Various advanced users have added or modified hardware for OpenWrt supported boards. Naturally those mods can't be accepted in the repository, so users of those modifications need to do full buildroot build. This means almost every addition of package needs another rebuild and flashing of new firmware complicating already running setup. Fortunately ImageBuilder has almost all necessary resources to rebuild Device Tree Blob (DTB), which almost all targets rely on to describe the hardware. Using ImageBuilder to build modified firmware cuts necessary time to few minutes. Another benefit is ability to use official package repository, esspecialy for kmods, which otherwise would conflict with kernel package hash. Thus I'm introducing this patch applicable directly on 24.10.x ImageBuilder for ease of testing and comments. This patch is "would be" result of apllying paches from this tree [1], except _get_bindings target which downloads SDK to copy matching dt-bindings. Some devices need kernel+dtb wrapped in some kind of loader, so REBUILD_DTB option downloads matching toolchain, which alows to recompile the loader. The REBUILD_DTB option is limited to release artifacts, since SNAPSHOT(s) artifacts are ephemeral, so using outdated ImageBuilder from snapshots directory won't cause unnecessary strain on OpenWrt human resources.
Please test by modifying ImageBuilder dts in (depending on target) target/linux/(target)/dts or build_dir/target-*/linux-(target)/linux-(version)/arch/*/boot/dts and don't shy commenting on the issues. I've used these changes for a long time on ath79 or ramips, and because questions about modifying firmware, which has still full benefit of official repo packages, pop up frequently, I've decided to share this and prepare patches for inclusion in official repo after initial test and comment round. 1. https://github.com/tmn505/openwrt/tree/rebuild-dtb Signed-off-by: Tomasz Maciej Nowak <tmn...@gmail.com> --- Makefile | 77 ++++++++++++++++++++++++++++++++++++++++++++++-- include/image.mk | 11 ++----- 2 files changed, 77 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index e9e08fb2765b..8ccbb66423b6 100644 --- a/Makefile +++ b/Makefile @@ -54,6 +54,15 @@ image: make image DISABLED_SERVICES="<svc1> [<svc2> [<svc3> ..]]" # Which services in /etc/init.d/ should be disabled make image ADD_LOCAL_KEY=1 # store locally generated signing key in built images make image ROOTFS_PARTSIZE="<size>" # override the default rootfs partition size in MegaBytes +endef +$(eval $(call shexport,Helptext)) + +define HelptextRelease + make image REBUILD_DTB=1 # force rebuild of Device Tree Blob +endef +$(eval $(call shexport,HelptextRelease)) + +define HelptextContinued manifest: List "all" packages which get installed into the image. @@ -77,10 +86,14 @@ package_depends: make package_depends PACKAGE="<pkg>" endef -$(eval $(call shexport,Helptext)) +$(eval $(call shexport,HelptextContinued)) help: FORCE echo "$$$(call shvar,Helptext)" + ifneq ($(VERSION_NUMBER),SNAPSHOT) + echo "$$$(call shvar,HelptextRelease)" + endif + echo "$$$(call shvar,HelptextContinued)" # override variables from rules.mk @@ -266,10 +279,12 @@ build_image: FORCE @echo Building images... rm -rf $(BUILD_DIR)/json_info_files/ if [ -d "target/linux/feeds/$(BOARD)" ]; then \ - $(NO_TRACE_MAKE) -C target/linux/feeds/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \ + $(NO_TRACE_MAKE) -C target/linux/feeds/$(BOARD)/image install TARGET_BUILD=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \ + $(if $(REBUILD_DTB),IB=REBUILD_DTB,IB=1) \ $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)"); \ else \ - $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 IB=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \ + $(NO_TRACE_MAKE) -C target/linux/$(BOARD)/image install TARGET_BUILD=1 EXTRA_IMAGE_NAME="$(EXTRA_IMAGE_NAME)" \ + $(if $(REBUILD_DTB),IB=REBUILD_DTB,IB=1) \ $(if $(USER_PROFILE),PROFILE="$(USER_PROFILE)"); \ fi @@ -331,9 +346,65 @@ else endif endif +ifneq ($(VERSION_NUMBER),SNAPSHOT) +HOST_OS:=$(shell uname) +HOST_ARCH:=$(shell uname -m) +TARGET_URL:=$(VERSION_REPO)/targets/$(BOARD)/$(SUBTARGET) +TOOLCHAIN_NAME:=$(VERSION_DIST_SANITIZED)-toolchain-$(if $(CONFIG_VERSION_FILENAMES),$(VERSION_NUMBER)-)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))_gcc-$(GCCV)$(DIR_SUFFIX).$(HOST_OS)-$(HOST_ARCH) +TOOLCHAIN_HASH:=$(shell wget -q -O- $(TARGET_URL)/sha256sums | awk '/$(TOOLCHAIN_NAME)/ {printf $$1}') + +_get_toolchain: FORCE + ifeq ($(TOOLCHAIN_HASH),) + @echo "Cant't obtain checksum for toolchain archive from $(TARGET_URL)/sha256sums" + @exit 1 + else + mkdir -p $(DL_DIR) + DOWNLOAD_CHECK_CERTIFICATE=1 $(SCRIPT_DIR)/download.pl \ + $(DL_DIR) \ + $(TOOLCHAIN_NAME).tar.zst \ + $(TOOLCHAIN_HASH) \ + $(TARGET_URL) + $(TAR) -x --strip-components=1 \ + -f $(DL_DIR)/$(TOOLCHAIN_NAME).tar.zst \ + -C $(TOPDIR)/staging_dir \ + $(TOOLCHAIN_NAME)/$(TOOLCHAIN_DIR_NAME) + endif + +SDK_NAME:=$(VERSION_DIST_SANITIZED)-sdk-$(if $(CONFIG_VERSION_FILENAMES),$(VERSION_NUMBER)-)$(BOARD)$(if $(SUBTARGET),-$(SUBTARGET))_gcc-$(GCCV)$(DIR_SUFFIX).$(HOST_OS)-$(HOST_ARCH) +SDK_HASH:=$(shell wget -q -O- $(TARGET_URL)/sha256sums | awk '/$(SDK_NAME)/ {printf $$1}') + +_get_bindings: FORCE + ifeq ($(SDK_HASH),) + @echo "Cant't obtain checksum for sdk archive from $(TARGET_URL)/sha256sums" + @exit 1 + else + mkdir -p \ + $(DL_DIR) \ + $(LINUX_DIR)/include \ + $(TMP_DIR) + DOWNLOAD_CHECK_CERTIFICATE=1 $(SCRIPT_DIR)/download.pl \ + $(DL_DIR) \ + $(SDK_NAME).tar.zst \ + $(SDK_HASH) \ + $(TARGET_URL) + $(TAR) -x \ + -f $(DL_DIR)/$(SDK_NAME).tar.zst \ + -C $(TMP_DIR) + $(CP) -L \ + $(TMP_DIR)/$(SDK_NAME)/build_dir/$(TARGET_DIR_NAME)/linux-$(BOARD)_$(SUBTARGET)/linux-$(LINUX_VERSION)/include/dt-bindings \ + $(LINUX_DIR)/include + endif +endif + image: $(MAKE) -s _check_profile $(MAKE) -s _check_keys + ifneq ($(VERSION_NUMBER),SNAPSHOT) + ifeq ($(REBUILD_DTB),1) + $(MAKE) -s _get_toolchain + $(MAKE) -s _get_bindings + endif + endif (unset PROFILE FILES PACKAGES MAKEFLAGS; \ $(MAKE) -s _call_image \ $(if $(PROFILE),USER_PROFILE="$(PROFILE_FILTER)") \ diff --git a/include/image.mk b/include/image.mk index 9a4dff2167a1..f27f18513eb5 100644 --- a/include/image.mk +++ b/include/image.mk @@ -210,7 +210,7 @@ endef # $(3) extra CPP flags # $(4) extra DTC flags define Image/BuildDTB/sub - $(TARGET_CROSS)cpp -nostdinc -x assembler-with-cpp \ + $(if IB,,$(TARGET_CROSS))cpp -nostdinc -x assembler-with-cpp \ $(DTS_CPPFLAGS) \ -I$(DTS_DIR) \ -I$(DTS_DIR)/include \ @@ -662,7 +662,6 @@ define Device/Build/compile endef -ifndef IB define Device/Build/dtb ifndef BUILD_DTS_$(1) BUILD_DTS_$(1) := 1 @@ -684,7 +683,6 @@ define Device/Build/dtbo endif endef -endif define Device/Build/kernel $$(eval $$(foreach dts,$$(DEVICE_DTS), \ @@ -705,10 +703,7 @@ define Device/Build/kernel $(call Device/Export,$$(KDIR_KERNEL_IMAGE),$(1)) $(BIN_DIR)/$$(KERNEL_IMAGE): $$(KDIR_KERNEL_IMAGE) cp $$^ $$@ - ifndef IB - ifdef CONFIG_IB - install: $$(KDIR_KERNEL_IMAGE) - endif + ifneq ($(IB),1) $$(KDIR_KERNEL_IMAGE): $(KDIR)/$$(KERNEL_NAME) $(CURDIR)/Makefile $$(KERNEL_DEPENDS) image_prepare @rm -f $$@ $$(call concat_cmd,$$(KERNEL)) @@ -932,7 +927,7 @@ define BuildImage clean: image_prepare: - ifeq ($(IB),) + ifneq ($(IB),1) .PHONY: download prepare compile compile-dtb clean image_prepare kernel_prepare install install-images compile: $(call Build/Compile) -- 2.49.0 _______________________________________________ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/mailman/listinfo/openwrt-devel