#1049991 arm-trusted-firmware: suggestions to improve the maintability of debian/rules

#1049991#5
Date:
2023-08-17 23:20:02 UTC
From:
To:
Hello.

The attached patch arguably improves debian/rules.

The ediff mode of emacs provides a more useful overview of the changes
than plain diff or gitk.
According to the test described at the end of the commit log, the new
version executes the same shell commands than before.

As usual… thanks for maintaining this package.
I hope this will simplify your work.

#1049991#10
Date:
2023-12-07 09:40:08 UTC
From:
To:
Hello.

I'm also interested in keeping the d/rules file easier to maintain. E.g. I want to build for the imx8mm platform in debug and release mode, which is currently not possible since $(platforms) and $(platforms_nodebug) will evaluate to the same name, thus I'll have an explicit target defined twice.

Best Regards

#1049991#15
Date:
2025-11-01 04:23:43 UTC
From:
To:
Hello.
An improved suggestion is attached, as as sequence of small commits.
I have run
  DEB_HOST_ARCH=arm64 debian/rules -n override_dh_auto_build | sed 's/ *; */\n/g'
initially and after each commit, the differences seem expected.
I hope this will be useful.

#1049991#20
Date:
2026-02-26 01:47:34 UTC
From:
To:
Hello.

This new version is rebased on debian/latest and way prettier.

# sbuild --host=arm64 --profiles=pkg.arm-trusted-firmware.notools
works with theses patches applied on top of tag debian/2.12.1+dfsg-1,
except the rk3* platforms.

The rk3* failure seems unrelated, as raw debian/2.12.1+dfsg-1 also
fails (on my configuration).
----
----  The rk3399 failure, just in case.
----
	make -j2 INSTALL="install --strip-program=true" PKG_CONFIG=aarch64-linux-gnu-pkg-config CXX=aarch64-linux-gnu-g\+\+ CC=aarch64-linux-gnu-gcc V=1 DEBUG=1 PLAT=rk3399 bl31
make[2]: Entering directory '/build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg'
mkdir -p '/build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg/build/rk3399/debug/bl31/'
mkdir -p '/build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg/build/rk3399/debug/m0/'
mkdir -p '/build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg/build/rk3399/debug/bl31/bl31/'
mkdir -p '/build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg/build/rk3399/debug/libfdt/'
mkdir -p '/build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg/build/rk3399/debug/lib/'
mkdir -p '/build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg/build/rk3399/debug/libc/'
[...]
'aarch64-linux-gnu-gcc' [...] /build/rk3399/debug/libfdt/fdt.o
'arm-none-eabi-gcc' -g -mcpu=cortex-m0 -mthumb -Wall -O3 -nostdlib -mfloat-abi=soft -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-common 	 -Iinclude/ -I../../include/shared/ -MMD -MT /build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg/build/rk3399/debug/m0/dram.o -c src/dram.c -o /build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg/build/rk3399/debug/m0/dram.o
/usr/bin/arm-none-eabi-gcc: 1: Syntax error: word unexpected (expecting ")")
make[3]: *** [Makefile:116: /build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg/build/rk3399/debug/m0/dram.o] Error 2
make[3]: Leaving directory '/build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg/plat/rockchip/rk3399/drivers/m0'
make[2]: *** [plat/rockchip/rk3399/platform.mk:109: /build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg/build/rk3399/debug/m0/rk3399m0.bin] Error 2
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg'
dh_auto_build: error: make -j2 INSTALL="install --strip-program=true" PKG_CONFIG=aarch64-linux-gnu-pkg-config CXX=aarch64-linux-gnu-g\+\+ CC=aarch64-linux-gnu-gcc V=1 DEBUG=1 PLAT=rk3399 bl31 returned exit code 2
install: cannot stat 'build/rk3399//debug/bl31/bl31.elf': No such file or directory
make[1]: *** [debian/rules:99: rk3399] Error 1
make[1]: Leaving directory '/build/reproducible-path/arm-trusted-firmware-2.12.1+dfsg'
make: *** [debian/rules:87: binary-arch] Error 2
dpkg-buildpackage: error: debian/rules binary-arch subprocess failed with exit status 2
---- ---- [PATCH 1/3] debian/rules: replace a loop with multiple arguments to the same command ---- --- a/debian/rules +++ b/debian/rules @@ -73,9 +73,7 @@ define build_platform $(eval board := $(if $(filter k3,$(platform)),lite,)) $(foreach subplatform, $(subplatforms), \ CROSS_COMPILE=aarch64-linux-gnu- CFLAGS=--param=min-pagesize=0 LDFLAGS= dh_auto_build -- V=$(VERBOSE) DEBUG=$(debug) $($(subplatform)_assigns) PLAT=$(platform) $(make_target) ; \ - $(foreach target, $(targets), \ - install -m644 build/$(platform)/$(board)/$(buildtype)/$(target) -Dt build/renamed/$(subplatform) ; \ - ) \ + install -m644 $(targets:%=build/$(platform)/$(board)/$(buildtype)/%) -Dt build/renamed/$(subplatform) ; \ # For each subplatform, make is called using the same PLAT variable. If # the build is not cleaned between each call, objects will remain the # same, without rebuilding them.
---- ---- [PATCH 2/3] debian/rules: group references to a given platform ---- A global list causes a conflict between any two commits enabling/disabling distinct platforms. --- a/debian/rules +++ b/debian/rules @@ -14,7 +14,8 @@ else VERBOSE=1 endif
---- ---- [PATCH 3/3] Improve debian/rules ---- Iterate on builds instead of PLATs then variants. The configuration is slightly more verbose but more flexible. For example, these two lines build imx8mm twice as requested in https://bugs.debian.org/1049991. platforms += imx8mm_bis imx8mm_bis_buildtype := release Iterate with Make instead of sh, so that commands are logged and their exit status checked. Rename the binaries instead of copying them before a clean. --- a/debian/rules +++ b/debian/rules @@ -14,80 +14,89 @@ else VERBOSE=1 endif +DEBUGrelease := 0 +DEBUGdebug := 1 + +# Each "platform" is a phony target in debian/rules. All platforms +# share a generic recipe delegating to the upstream Makefile and +# configured by the following variables. +# The target in the upstream Makefile: +make_target := bl31 +# The upstream Make variable with the same name: +PLAT = $@ +# Path component for binary results (release/debug when DEBUG is 0/1): +buildtype := debug +# The binary result(s): +targets = build/$(PLAT)/$(buildtype)/bl31.bin +# Upstream Make variables passed on the command line: +assigns = DEBUG=$(DEBUG$(buildtype)) PLAT=$(PLAT) + platforms := g12a gxbb sun50i_a64 rpi3 rpi4 rpi5 # Disable building of imx8mq, as it is not well supported upstream. -#platforms_nodebug := imx8mq +# platforms += imx8mq +imx8mq: buildtype := release # By default, iMX8MN uses UART2 console. However, other boards supported # upstream (e.g. Variscite VAR-SOM-MX8M-NANO board) uses UART4. # Add two subplatforms for imx8mn platform: # * imx8mn: default configuration # * imx8mn_uart4: console set to UART4 -platforms += imx8mn -imx8mn_subplatforms := imx8mn imx8mn_uart4 -imx8mn_uart4_assigns := IMX_BOOT_UART_BASE=0x30a60000 +platforms += imx8mn imx8mn_uart4 +imx8mn_uart4: PLAT := imx8mn +imx8mn_uart4: assigns += IMX_BOOT_UART_BASE=0x30a60000 # By default, iMX8MM uses UART2 console. However, other boards # use other UARTs -platforms += imx8mm -imx8mm_subplatforms := imx8mm imx8mm_uart1 imx8mm_uart3 imx8mm_uart4 -imx8mm_uart1_assigns := IMX_BOOT_UART_BASE=0x30860000 -imx8mm_uart3_assigns := IMX_BOOT_UART_BASE=0x30880000 -imx8mm_uart4_assigns := IMX_BOOT_UART_BASE=0x30A60000 +platforms += imx8mm imx8mm_uart1 imx8mm_uart3 imx8mm_uart4 +imx8mm_uart1 imx8mm_uart3 imx8mm_uart4: PLAT := imx8mm +imx8mm_uart1: assigns += IMX_BOOT_UART_BASE=0x30860000 +imx8mm_uart3: assigns += IMX_BOOT_UART_BASE=0x30880000 +imx8mm_uart4: assigns += IMX_BOOT_UART_BASE=0x30A60000 # Same for iMX8MP -platforms += imx8mp -imx8mp_subplatforms := imx8mp imx8mp_uart1 imx8mp_uart3 imx8mp_uart4 -imx8mp_uart1_assigns := IMX_BOOT_UART_BASE=0x30860000 -imx8mp_uart3_assigns := IMX_BOOT_UART_BASE=0x30880000 -imx8mp_uart4_assigns := IMX_BOOT_UART_BASE=0x30A60000 +platforms += imx8mp imx8mp_uart1 imx8mp_uart3 imx8mp_uart4 +imx8mp_uart1 imx8mp_uart3 imx8mp_uart4: PLAT := imx8mp +imx8mp_uart1: assigns += IMX_BOOT_UART_BASE=0x30860000 +imx8mp_uart3: assigns += IMX_BOOT_UART_BASE=0x30880000 +imx8mp_uart4: assigns += IMX_BOOT_UART_BASE=0x30A60000 platforms += k3 -k3_assigns := TARGET_BOARD=lite +k3: assigns += TARGET_BOARD=lite +k3: targets = build/$(PLAT)/lite/$(buildtype)/bl31.bin # TF-A's regulator setup breaks Ethernet on some H6 boards, # so make it optional by having two subplatforms: # * sun50i_h6: default configuration # * sun50i_h6_no_pmic: skip regulator setup -platforms += sun50i_h6 -sun50i_h6_subplatforms := sun50i_h6 sun50i_h6_no_pmic -sun50i_h6_no_pmic_assigns := SUNXI_SETUP_REGULATORS=0 +platforms += sun50i_h6 sun50i_h6_no_pmic +sun50i_h6_no_pmic: PLAT := sun50i_h6 +sun50i_h6_no_pmic: assigns += SUNXI_SETUP_REGULATORS=0 platforms += rk3328 rk3399 rk3568 rk3588 -rk3328_targets := bl31/bl31.elf -rk3399_targets := bl31/bl31.elf -rk3568_targets := bl31/bl31.elf -rk3588_targets := bl31/bl31.elf - -platforms += rcar -rcar_subplatforms := rcar_uclb_h3 rcar_uclb_m3w rcar_uclb_m3n -rcar_uclb_h3_assigns := LSI=H3 RCAR_DRAM_SPLIT=1 RCAR_GEN3_ULCB=1 PMIC_LEVEL_MODE=0 RCAR_DRAM_LPDDR4_MEMCONF=0 SPD=opteed RCAR_LOSSY_ENABLE=1 -rcar_uclb_m3n_assigns := LSI=M3N RCAR_GEN3_ULCB=1 PMIC_LEVEL_MODE=0 RCAR_DRAM_LPDDR4_MEMCONF=0 SPD=opteed RCAR_LOSSY_ENABLE=1 -rcar_uclb_m3w_assigns := LSI=M3 RCAR_DRAM_SPLIT=2 RCAR_GEN3_ULCB=1 PMIC_LEVEL_MODE=0 RCAR_DRAM_LPDDR4_MEMCONF=0 SPD=opteed RCAR_LOSSY_ENABLE=1 +rk3328 rk3399 rk3568 rk3588: targets = build/$(PLAT)/$(buildtype)/bl31/bl31.elf