Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 May 2025 07:03:08 GMT
From:      Colin Percival <cperciva@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 95d87d5f5655 - releng/14.3 - arm: Improve the creation of kernel.bin
Message-ID:  <202505050703.545738gj036984@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch releng/14.3 has been updated by cperciva:

URL: https://cgit.FreeBSD.org/src/commit/?id=95d87d5f5655008def3f7658820ee7dd6191236f

commit 95d87d5f5655008def3f7658820ee7dd6191236f
Author:     Michal Meloun <mmel@FreeBSD.org>
AuthorDate: 2024-11-03 12:15:33 +0000
Commit:     Colin Percival <cperciva@FreeBSD.org>
CommitDate: 2025-05-05 07:01:44 +0000

    arm: Improve the creation of kernel.bin
    
    Instead of relinking the kernel without elf headers, replace them with
    a binary blob of the same length starting with a jump to the kernel's start
    address. This ensures that all symbols stay at the same offsets as in
    the original kernel, so kernel.debug remains valid also for kernel.bin.
    
    Also ensure that the awk script used runs with  the neutral locale defined.
    Awk 'write' is a locale compilant, and  script is used to write binary data
    to a file, so it needs to ensure that  bytes > 127 are written unchanged.
    
    While I'm on, set the neutral locale also for arm64, where the same script is
    used to generate the kernel booti image.
    
    Reviewed by:    emaste, imp
    Approved by:    re (cperciva)
    Differential Revision:  https://reviews.freebsd.org/D47488
    
    (cherry picked from commit ba045ba49dedb068ba2f0e13fbb1c1a91fde8333)
    (cherry picked from commit bec5167645b5d157a1c980099162362f115ccbfe)
---
 sys/conf/Makefile.arm   | 39 ++++++++++++++++++++-------------------
 sys/conf/Makefile.arm64 |  1 +
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/sys/conf/Makefile.arm b/sys/conf/Makefile.arm
index 5195191e0156..3f4248c85cd0 100644
--- a/sys/conf/Makefile.arm
+++ b/sys/conf/Makefile.arm
@@ -59,6 +59,7 @@ KERNVIRTADDR= 0xc0000000
 # "ELF for the ARM architecture" for more info on the mapping symbols.
 SYSTEM_LD= \
 	${SYSTEM_LD_BASECMD} \
+	    --Map=/usr2/Meloun/ld.map \
 	    --defsym='text_start=kernbase + SIZEOF_HEADERS' \
 	    -o ${.TARGET} ${SYSTEM_OBJS} vers.o; \
 	$(OBJCOPY) \
@@ -66,25 +67,6 @@ SYSTEM_LD= \
 	    --strip-symbol='$$[adt]*' \
 	    ${.TARGET}
 
-# Generate the .bin (no elf headers) kernel as an extra build output.
-# We must relink to generate the .bin kernel, because without headers the
-# location of everything changes.  We also strip the ARM marker symbols.
-KERNEL_EXTRA+= ${KERNEL_KO}.bin
-KERNEL_EXTRA_INSTALL+= ${KERNEL_KO}.bin
-
-${KERNEL_KO}.bin: ${SYSTEM_DEP} vers.o
-	@echo "linking ${.TARGET}"
-	@${SYSTEM_LD_BASECMD} \
-	    --defsym='text_start=kernbase' \
-	    -o ${.TARGET} ${SYSTEM_OBJS} vers.o
-	${SIZE} ${.TARGET}
-	@${OBJCOPY} \
-	    --wildcard \
-	    --strip-symbol='$$[adt]*' \
-	    --output-target=binary \
-	    ${.TARGET}
-	@chmod 755 ${.TARGET}
-
 # hack because genassym.c includes sys/bus.h which includes these.
 genassym.o: bus_if.h device_if.h
 
@@ -105,3 +87,22 @@ CLEAN+=	${KERNEL_KO}.bin
 %RULES
 	
 .include "$S/conf/kern.post.mk"
+
+# Generate the .bin (no elf headers) kernel
+# Copy the kernel to directly executable format (the elf headers are
+# stripped and a binary head blob with jump to kernel start address is
+# prepended), saving the output in a temp file.
+# We also strip arm "marker" symbols which are used only by elf toolchains. Read
+# the symbols from kernel.full and pass  them to arm_kernel_boothdr.awk, which
+# generates a binary header blob that goes on the front of the stripped kernel.
+# Cat the header blob and the temp file together to make the kernel.bin file.
+${KERNEL_KO}.bin: ${FULLKERNEL}
+	@${OBJCOPY} --wildcard --strip-symbol='$$[adtx]*' \
+	    --output-target=binary ${FULLKERNEL} ${.TARGET}.temp
+	@{ ${NM} ${FULLKERNEL} | \
+	    LC_ALL=C \
+	    ${AWK} -f $S/tools/arm_kernel_boothdr.awk -v hdrtype=v7jump && \
+	    cat ${.TARGET}.temp; \
+	 } > ${.TARGET}
+	@rm ${.TARGET}.temp
+	@echo "created ${.TARGET} from ${.ALLSRC}"
diff --git a/sys/conf/Makefile.arm64 b/sys/conf/Makefile.arm64
index 5e706549486a..69717e98a889 100644
--- a/sys/conf/Makefile.arm64
+++ b/sys/conf/Makefile.arm64
@@ -95,6 +95,7 @@ ${KERNEL_KO}.bin: ${FULLKERNEL}
 	@${OBJCOPY} --wildcard --strip-symbol='$$[adtx]*' \
 	    --output-target=binary ${FULLKERNEL} ${.TARGET}.temp
 	@{ ${NM} ${FULLKERNEL} | \
+	    LC_ALL=C \
 	    ${AWK} -f $S/tools/arm_kernel_boothdr.awk -v hdrtype=v8booti && \
 	    cat ${.TARGET}.temp; \
 	 } > ${.TARGET}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202505050703.545738gj036984>