Source: arm-trusted-firmware
Followup-For: Bug #1049991

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
 
-platforms := g12a gxbb imx8mm imx8mn imx8mp k3 sun50i_a64 sun50i_h6 rcar 
rk3328 rk3399 rk3568 rk3588 rpi3 rpi4 rpi5
+platforms := g12a gxbb sun50i_a64 rpi3 rpi4 rpi5
+
 # Disable building of imx8mq, as it is not well supported upstream.
 #platforms_nodebug := imx8mq
 
@@ -23,36 +24,43 @@ platforms := g12a gxbb imx8mm imx8mn imx8mp k3 sun50i_a64 
sun50i_h6 rcar rk3328
 # 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
 
 # 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
 
 # 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 += k3
 k3_assigns := TARGET_BOARD=lite
 
 # 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 += 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

----
----  [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
 
-rcar_targets := bl31.srec bl2.srec
-rcar_make_target := rcar
+platforms += rcar_uclb_h3 rcar_uclb_m3w rcar_uclb_m3n
+rcar_uclb_h3 rcar_uclb_m3n rcar_uclb_m3w: PLAT := rcar
+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
+rcar_uclb_h3 rcar_uclb_m3n rcar_uclb_m3w: targets = 
build/$(PLAT)/$(buildtype)/bl31.srec build/$(PLAT)/$(buildtype)/bl2.srec
+rcar_uclb_h3 rcar_uclb_m3n rcar_uclb_m3w: make_target := rcar
 
 # Always set CROSS_COMPILE, which also works for native builds.
-define build_platform
-       $(eval platform := $(1))
-       $(eval debug := $(2))
-       $(eval buildtype := $(3))
-       $(eval subplatforms := $(if $($(platform)_subplatforms), 
$($(platform)_subplatforms), $(platform)))
-       $(eval targets := $(if $($(platform)_targets), $($(platform)_targets), 
bl31.bin))
-       $(eval make_target := $(if $($(platform)_make_target), 
$($(platform)_make_target), bl31))
-       # board needs to be set to "lite" for k3 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) ; \
-               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.
-               make DEBUG=$(debug) $($(subplatform)_assigns) PLAT=$(platform) 
clean ; \
-       )
-endef
+$(platforms): export CROSS_COMPILE := aarch64-linux-gnu-
+$(platforms): export CFLAGS := --param=min-pagesize=0
+$(platforms): export LDFLAGS :=
+$(platforms):
+       dh_auto_build -- V=$(VERBOSE) $(assigns) $(make_target)
+  # Next platfom may share PLAT and buildtype.  In order to force the
+  # upstream Makefile to rebuild all objects even in this case, move
+  # the results and clean.
+       mkdir -p build/renamed/$@
+       mv -f $(targets) build/renamed/$@
+       chmod 644 build/renamed/$@/*
+       make $(assigns) clean
 
 %:
        dh $@
@@ -100,11 +109,7 @@ ifeq ($(filter 
pkg.arm-trusted-firmware.notools,$(DEB_BUILD_PROFILES)),)
 endif
 # Only build firmware on arm64.
 ifeq ($(DEB_HOST_ARCH),arm64)
-  override_dh_auto_build: $(platforms) $(platforms_nodebug)
-  $(platforms):
-       $(call build_platform,$@,1,debug)
-  $(platforms_nodebug):
-       $(call build_platform,$@,0,release)
+  override_dh_auto_build: $(platforms)
 endif
 
 override_dh_installchangelogs:
>From f701a8498a135af142149e90cce99aa09c9002db Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <[email protected]>
Date: Sat, 1 Nov 2025 02:59:00 +0100
Subject: [PATCH 1/3] debian/rules: replace a loop with multiple arguments to
 the same command

---
 debian/rules | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/debian/rules b/debian/rules
index c9c5aaffc..472c13300 100755
--- 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.
-- 
2.47.3

>From c3f95e8d53a0274a6ba6cf438efece17302d34c3 Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <[email protected]>
Date: Sat, 1 Nov 2025 03:07:32 +0100
Subject: [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.
---
 debian/rules | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/debian/rules b/debian/rules
index 472c13300..0066cc249 100755
--- a/debian/rules
+++ b/debian/rules
@@ -14,7 +14,8 @@ else
 VERBOSE=1
 endif
 
-platforms := g12a gxbb imx8mm imx8mn imx8mp k3 sun50i_a64 sun50i_h6 rcar rk3328 rk3399 rk3568 rk3588 rpi3 rpi4 rpi5
+platforms := g12a gxbb sun50i_a64 rpi3 rpi4 rpi5
+
 # Disable building of imx8mq, as it is not well supported upstream.
 #platforms_nodebug := imx8mq
 
@@ -23,36 +24,43 @@ platforms := g12a gxbb imx8mm imx8mn imx8mp k3 sun50i_a64 sun50i_h6 rcar rk3328
 # 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
 
 # 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
 
 # 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 += k3
 k3_assigns := TARGET_BOARD=lite
 
 # 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 += 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
-- 
2.47.3

>From 8313b0cb0b9e882deac309d93336475ef639875c Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <[email protected]>
Date: Thu, 26 Feb 2026 01:50:46 +0100
Subject: [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.
---
 debian/rules | 111 +++++++++++++++++++++++++++------------------------
 1 file changed, 58 insertions(+), 53 deletions(-)

diff --git a/debian/rules b/debian/rules
index 0066cc249..6bf4109d6 100755
--- 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
 
-rcar_targets := bl31.srec bl2.srec
-rcar_make_target := rcar
+platforms += rcar_uclb_h3 rcar_uclb_m3w rcar_uclb_m3n
+rcar_uclb_h3 rcar_uclb_m3n rcar_uclb_m3w: PLAT := rcar
+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
+rcar_uclb_h3 rcar_uclb_m3n rcar_uclb_m3w: targets = build/$(PLAT)/$(buildtype)/bl31.srec build/$(PLAT)/$(buildtype)/bl2.srec
+rcar_uclb_h3 rcar_uclb_m3n rcar_uclb_m3w: make_target := rcar
 
 # Always set CROSS_COMPILE, which also works for native builds.
-define build_platform
-	$(eval platform := $(1))
-	$(eval debug := $(2))
-	$(eval buildtype := $(3))
-	$(eval subplatforms := $(if $($(platform)_subplatforms), $($(platform)_subplatforms), $(platform)))
-	$(eval targets := $(if $($(platform)_targets), $($(platform)_targets), bl31.bin))
-	$(eval make_target := $(if $($(platform)_make_target), $($(platform)_make_target), bl31))
-	# board needs to be set to "lite" for k3 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) ; \
-		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.
-		make DEBUG=$(debug) $($(subplatform)_assigns) PLAT=$(platform) clean ; \
-	)
-endef
+$(platforms): export CROSS_COMPILE := aarch64-linux-gnu-
+$(platforms): export CFLAGS := --param=min-pagesize=0
+$(platforms): export LDFLAGS :=
+$(platforms):
+	dh_auto_build -- V=$(VERBOSE) $(assigns) $(make_target)
+  # Next platfom may share PLAT and buildtype.  In order to force the
+  # upstream Makefile to rebuild all objects even in this case, move
+  # the results and clean.
+	mkdir -p build/renamed/$@
+	mv -f $(targets) build/renamed/$@
+	chmod 644 build/renamed/$@/*
+	make $(assigns) clean
 
 %:
 	dh $@
@@ -100,11 +109,7 @@ ifeq ($(filter pkg.arm-trusted-firmware.notools,$(DEB_BUILD_PROFILES)),)
 endif
 # Only build firmware on arm64.
 ifeq ($(DEB_HOST_ARCH),arm64)
-  override_dh_auto_build: $(platforms) $(platforms_nodebug)
-  $(platforms):
-	$(call build_platform,$@,1,debug)
-  $(platforms_nodebug):
-	$(call build_platform,$@,0,release)
+  override_dh_auto_build: $(platforms)
 endif
 
 override_dh_installchangelogs:
-- 
2.47.3

Reply via email to