From 2e6e338c83344761cc002cbbad592b945f160e50 Mon Sep 17 00:00:00 2001 From: Paul Scheffler Date: Thu, 14 Nov 2024 20:14:51 +0100 Subject: [PATCH 1/2] sw: Add target-aware linking for BMPs --- sw/sw.mk | 36 ++++++++++++++----- .../{axirt_budget.c => axirt_budget.spm.c} | 0 ...t_isolate.c => axirt_budget_isolate.spm.c} | 0 sw/tests/{axirt_hello.c => axirt_hello.spm.c} | 0 sw/tests/{dma_2d.c => dma_2d.spm.c} | 0 5 files changed, 28 insertions(+), 8 deletions(-) rename sw/tests/{axirt_budget.c => axirt_budget.spm.c} (100%) rename sw/tests/{axirt_budget_isolate.c => axirt_budget_isolate.spm.c} (100%) rename sw/tests/{axirt_hello.c => axirt_hello.spm.c} (100%) rename sw/tests/{dma_2d.c => dma_2d.spm.c} (100%) diff --git a/sw/sw.mk b/sw/sw.mk index da5184427..7daab152f 100644 --- a/sw/sw.mk +++ b/sw/sw.mk @@ -100,14 +100,21 @@ CHS_SW_GEN_HDRS += $(OTPROOT)/.generated %.o: %.S $(CHS_SW_GEN_HDRS) $(CHS_SW_CC) $(CHS_SW_INCLUDES) $(CHS_SW_CCFLAGS) -c $< -o $@ +# Programs may specify a linking mode in their name, e.g. `helloworld.spm.c`. +# Tests with such infixes are built only for one linking mode, tests without them for all define chs_sw_ld_elf_rule .PRECIOUS: %.$(1).elf %.$(1).elf: $$(CHS_SW_LD_DIR)/$(1).ld %.o $$(CHS_SW_LIBS) $$(CHS_SW_CC) $$(CHS_SW_INCLUDES) -T$$< $$(CHS_SW_LDFLAGS) -o $$@ $$*.o $$(CHS_SW_LIBS) + +%.$(1).elf: $$(CHS_SW_LD_DIR)/$(1).ld %.$(1).o $$(CHS_SW_LIBS) + $$(CHS_SW_CC) $$(CHS_SW_INCLUDES) -T$$< $$(CHS_SW_LDFLAGS) -o $$@ $$*.$(1).o $$(CHS_SW_LIBS) endef -$(foreach link,$(patsubst $(CHS_SW_LD_DIR)/%.ld,%,$(wildcard $(CHS_SW_LD_DIR)/*.ld)),$(eval $(call chs_sw_ld_elf_rule,$(link)))) +CHS_SW_LINK_MODES ?= $(patsubst $(CHS_SW_LD_DIR)/%.ld,%,$(wildcard $(CHS_SW_LD_DIR)/*.ld)) + +$(foreach link,$(CHS_SW_LINK_MODES),$(eval $(call chs_sw_ld_elf_rule,$(link)))) %.dump: %.elf $(CHS_SW_OBJDUMP) -d -S $< > $@ @@ -158,11 +165,24 @@ $(CHS_SW_DIR)/boot/linux.%.gpt.bin: $(CHS_SW_DIR)/boot/zsl.rom.bin $(CHS_SW_DIR) # Tests # ######### -CHS_SW_TEST_SRCS_S = $(wildcard $(CHS_SW_DIR)/tests/*.S) -CHS_SW_TEST_SRCS_C = $(wildcard $(CHS_SW_DIR)/tests/*.c) -CHS_SW_TEST_DRAM_DUMP = $(CHS_SW_TEST_SRCS_S:.S=.dram.dump) $(CHS_SW_TEST_SRCS_C:.c=.dram.dump) -CHS_SW_TEST_SPM_DUMP = $(CHS_SW_TEST_SRCS_S:.S=.spm.dump) $(CHS_SW_TEST_SRCS_C:.c=.spm.dump) -CHS_SW_TEST_SPM_ROMH = $(CHS_SW_TEST_SRCS_S:.S=.rom.memh) $(CHS_SW_TEST_SRCS_C:.c=.rom.memh) -CHS_SW_TEST_SPM_GPTH = $(CHS_SW_TEST_SRCS_S:.S=.gpt.memh) $(CHS_SW_TEST_SRCS_C:.c=.gpt.memh) +# Accumulate single-link-mode sources and corresponding .dump targets +define chs_sw_tests_add_rule +BLA += $(wildcard $(2)/*.$(1).c) +CHS_SW_TEST_LONE += $(wildcard $(2)/*.$(1).c) $(wildcard $(2)/*.$(1).S) +CHS_SW_TEST_DUMP += $(patsubst %.c,%.dump,$(wildcard $(2)/*.$(1).c)) $(patsubst %.S,%.dump,$(wildcard $(2)/*.$(1).S)) +endef + +# Accumulate tests for all link modes +$(foreach link,$(CHS_SW_LINK_MODES),$(eval $(call chs_sw_tests_add_rule,$(link),$(CHS_SW_DIR)/tests))) + +# Collect mode-agnostic tests, which should be build for all modes, and their .dump targets +CHS_SW_TEST_C_LALL = $(filter-out $(CHS_SW_TEST_LONE), $(wildcard $(CHS_SW_DIR)/tests/*.c)) +CHS_SW_TEST_S_LALL = $(filter-out $(CHS_SW_TEST_LONE), $(wildcard $(CHS_SW_DIR)/tests/*.S)) +$(foreach link,$(CHS_SW_LINK_MODES),$(eval CHS_SW_TEST_DUMP += $(CHS_SW_TEST_C_LALL:.c=.$(link).dump) $(CHS_SW_TEST_S_LALL:.S=.$(link).dump))) + +# Generate .memh targets for ROM-linked tests +CHS_SW_TEST_ROM_DUMP = $(filter %.rom.dump,$(CHS_SW_TEST_DUMP)) +CHS_SW_TESTS += $(CHS_SW_TEST_ROM_DUMP:.rom.dump=.rom.memh) $(CHS_SW_TEST_ROM_DUMP:.rom.dump=.gpt.memh) -CHS_SW_TESTS = $(CHS_SW_TEST_DRAM_DUMP) $(CHS_SW_TEST_SPM_DUMP) $(CHS_SW_TEST_SPM_ROMH) $(CHS_SW_TEST_SPM_GPTH) +# Add all dumps to test build +CHS_SW_TESTS += $(CHS_SW_TEST_DUMP) diff --git a/sw/tests/axirt_budget.c b/sw/tests/axirt_budget.spm.c similarity index 100% rename from sw/tests/axirt_budget.c rename to sw/tests/axirt_budget.spm.c diff --git a/sw/tests/axirt_budget_isolate.c b/sw/tests/axirt_budget_isolate.spm.c similarity index 100% rename from sw/tests/axirt_budget_isolate.c rename to sw/tests/axirt_budget_isolate.spm.c diff --git a/sw/tests/axirt_hello.c b/sw/tests/axirt_hello.spm.c similarity index 100% rename from sw/tests/axirt_hello.c rename to sw/tests/axirt_hello.spm.c diff --git a/sw/tests/dma_2d.c b/sw/tests/dma_2d.spm.c similarity index 100% rename from sw/tests/dma_2d.c rename to sw/tests/dma_2d.spm.c From 95b7e2b5c257fa87943c2904c10425d724cb4469 Mon Sep 17 00:00:00 2001 From: Paul Scheffler Date: Thu, 14 Nov 2024 21:25:07 +0100 Subject: [PATCH 2/2] docs/sw.md: Document target-aware linking of BMPs --- docs/um/sw.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/um/sw.md b/docs/um/sw.md index 671f4765f..a58b5b8ad 100644 --- a/docs/um/sw.md +++ b/docs/um/sw.md @@ -22,7 +22,11 @@ To build a baremetal program (here `sw/tests/helloworld.c`) executing from the S make sw/tests/helloworld.spm.elf ``` -To create the same program executing from DRAM, `sw/tests/helloworld.spm.dram` can instead be built from the same source. Depending on their assumptions and behavior, not all programs may be built to execute from both locations. +To create the same program executing from DRAM, `sw/tests/helloworld.dram.elf` can instead be built from the same source. + +Not all BMPs may be designed to be linked in multiple ways like `helloworld` above is. Linking is controlled by the linker scripts in `sw/link`. By convention, BMP main source files with a suffix are intended to only be linked with the corresponding script; for example, `sw/tests/dma_2d.spm.c` should only be linked against SPM using `sw/link/spm.ld`. + +When building BMPs, the toolchain will strip any suffixes corresponding to existing linker scripts. When running `make sw-all`, tests in `sw/tests` will be built only for their intended linking targets. Tests without suffixes, like `helloworld`, are assumed to be agnostic and will be built for all linking targets. ## Boot Flow