mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 3/3] kbuild: support generating stripped ELF files for PBL
Date: Wed, 13 Sep 2023 14:57:15 +0200	[thread overview]
Message-ID: <20230913125715.2142524-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230913125715.2142524-1-a.fatoum@pengutronix.de>

For testing remoteproc and ELF loading mechanisms, it can be useful
to have the consumed ELF files result from the barebox build itself.

The *.pblb intermediate artifacts can be used for this purpose, but they
are at least 64K larger than need be, because of generous alignment in
addition to debug and symbol information.

Let's add a separate %.elf target, that behaves like %.pblb with the
difference that the result is stripped and alignment of sections on-disk
is disabled.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 Makefile        |  4 ++--
 images/Makefile | 10 +++++++---
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index f86d76076fb7..0e579eb804f2 100644
--- a/Makefile
+++ b/Makefile
@@ -470,6 +470,7 @@ LDFLAGS_common += $(call ld-option,--no-warn-rwx-segments)
 
 LDFLAGS_barebox += $(LDFLAGS_common)
 LDFLAGS_pbl += $(LDFLAGS_common)
+LDFLAGS_elf += $(LDFLAGS_common) --nmagic -s
 
 export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
 export CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL PYTHON3 UTS_MACHINE
@@ -483,8 +484,7 @@ export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
 export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
 export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE
 export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
-export LDFLAGS_barebox
-export LDFLAGS_pbl
+export LDFLAGS_barebox LDFLAGS_pbl LDFLAGS_elf
 
 export CFLAGS_UBSAN
 export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE
diff --git a/images/Makefile b/images/Makefile
index c1cb56f5b189..9739a15c06ba 100644
--- a/images/Makefile
+++ b/images/Makefile
@@ -57,9 +57,9 @@ $(pbl-lds): $(obj)/../arch/$(SRCARCH)/lib/pbl.lds.S FORCE
 	$(call if_changed_dep,cpp_lds_S)
 
 quiet_cmd_elf__ ?= LD      $@
-      cmd_elf__ ?= $(LD) $(LDFLAGS_pbl) --gc-sections		\
+      cmd_elf__ ?= $(LD) $(LDFLAGS_$(patsubst .%,%,$(suffix $(@F)))) 	\
 		-e $(2) -Map $@.map $(LDFLAGS_$(@F)) -o $@		\
-		--defsym=__pbl_board_entry=$(2)  			\
+		--gc-sections --defsym=__pbl_board_entry=$(2)  		\
 		-T $(pbl-lds)						\
 		--whole-archive $(BAREBOX_PBL_OBJS) $(obj)/piggy.o	\
 		$(obj)/sha_sum.o
@@ -70,6 +70,10 @@ $(obj)/%.pbl: $(pbl-lds) $(BAREBOX_PBL_OBJS) $(obj)/piggy.o $(obj)/sha_sum.o FOR
 	$(call if_changed,elf__,$(*F))
 	$(call cmd,prelink__)
 
+$(obj)/%.elf: $(pbl-lds) $(BAREBOX_PBL_OBJS) $(obj)/piggy.o $(obj)/sha_sum.o FORCE
+	$(call if_changed,elf__,$(*F))
+	$(call cmd,prelink__)
+
 $(obj)/%.pblb: $(obj)/%.pbl FORCE
 	$(call if_changed,objcopy_bin,$(*F))
 	$(Q)$(OBJCOPY) -O binary --only-section=.missing_fw $< $@.missing-firmware
@@ -218,7 +222,7 @@ $(flash-link): $(link-dest) FORCE
 $(flash-list): $(image-y-path)
 	@for i in $^; do if [ -s $$i ]; then echo $$i; fi; done > $@
 
-clean-files := *.pbl *.pblb *.map start_*.imximg *.img barebox.z start_*.kwbimg \
+clean-files := *.pbl *.pblb *.elf *.map start_*.imximg *.img barebox.z start_*.kwbimg \
 	start_*.kwbuartimg *.socfpgaimg *.mlo *.t20img *.t20img.cfg *.t30img \
 	*.t30img.cfg *.t124img *.t124img.cfg *.mlospi *.mlo *.mxsbs *.mxssd *.rkimg \
 	start_*.simximg start_*.usimximg *.zynqimg *.image *.swapped *.missing-firmware
-- 
2.39.2




  parent reply	other threads:[~2023-09-13 12:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-13 12:57 [PATCH 0/3] ARM: support booting arbitrary ELF executables Ahmad Fatoum
2023-09-13 12:57 ` [PATCH 1/3] common: elf: support loading to address 0 Ahmad Fatoum
2023-09-13 12:57 ` [PATCH 2/3] ARM: add support for booting ELF executables Ahmad Fatoum
2023-09-13 12:57 ` Ahmad Fatoum [this message]
2023-09-21  8:18 ` [PATCH 0/3] ARM: support booting arbitrary " Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230913125715.2142524-4-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox