From nobody Sat May 03 10:09:05 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ZqNmf2Vhxz5v4vf; Sat, 03 May 2025 10:09:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZqNmd67l0z3gFJ; Sat, 03 May 2025 10:09:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746266945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Hnfewf72aX34+n7Zm5AUL6qYndJ5graRKxK719NOxiw=; b=jVymOeg84901Fs1bBlS3wVXkhvhmu8zLGSojYcc7ru+1gKn3qKT3GW1xdGdasm8KtEoG1U HucrMu2EO16xeT0EGjQpmB+VO4xuJtgoNGrvzpCGtMjB7aYNj1doXzAuVh2EpJMDbci/Iw mTg+52QtPzHOd0FL9j1T2DLYfsXQuaEzhSqtuqnnKrQX0AFkl9nleAn7FSc9aBJOPebm5g cCLCpEbdI0dExdsYBNDxghlLto3BBOQm+3lAq6JUrJoLpi06uh628JXlnkoHxoMCD5dY31 XGZlGSThQ7hfwGYnKaGlFOiTW1JjVtWWUuoz9Ygvd5xDiU5AiMf6J3yKOjGnZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746266945; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Hnfewf72aX34+n7Zm5AUL6qYndJ5graRKxK719NOxiw=; b=Mpwhlv57IFQ46i+jVVgzz3t+q7ldawNwoiJrgQbaBSlgnDzrAzPQ69rF9HarSadTtXz6Ua EVJsPlwAktmQeZbiu0kD7FnsjDR9F3zm7uEvBgHWaqw4A11dxRs7XhNP7YsPxywzm83xla WBj5/y/RPWilYHTYENsScan6j8993+wfoU9WHWI9VFY76rEzHvNqwsx93srNZ7+SVSLh8V 74KrnZGo7Oy6+6EuZJBpKj25/X82PTi0dJ1l9fUaaXRJW/G0pk3Y+KcCWtJmUONBBFFyMi g50oH+b/AW6Xfa/OdP1NBjLhJWZ6Ukapeuy4Htuisg3BRAGIOnAOxuGiluvjvw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1746266945; a=rsa-sha256; cv=none; b=G0mWke61bvFuhGgpJYXcCGGWILh/ajEFVe3JuK9W/iCXY/QY4V5IToBIaygfWdCh6BKIiL 5BUrIoHFUx3agLYLVgJGY0f586hOLCrqKdNkug9KHJ0nET4h5Sd3MUIEzO1Y/RougO+lWC hWQvozMyOEqxg5oaZjbLem4v68iVu6aTUb8xzbXwJg917N5HrjR8WhCB59g+6Z9mVUK0gg b01+9v59/M3x4qn/X4pSt0W2wlPOzc/bIQoilx3HNajUSM/IHOPuzzNfmu562w7Kd4SG5m u0aUjZvitbhwgmlDjxlV9B58fxBUnsQ4r8kBzSJ2ISYMip9FIH73SnjawojtfA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ZqNmd5fJgzfQB; Sat, 03 May 2025 10:09:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 543A95kJ062102; Sat, 3 May 2025 10:09:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 543A95jl062099; Sat, 3 May 2025 10:09:05 GMT (envelope-from git) Date: Sat, 3 May 2025 10:09:05 GMT Message-Id: <202505031009.543A95jl062099@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Michal Meloun Subject: git: bec5167645b5 - stable/14 - arm: Improve the creation of kernel.bin List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mmel X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: bec5167645b5d157a1c980099162362f115ccbfe Auto-Submitted: auto-generated The branch stable/14 has been updated by mmel: URL: https://cgit.FreeBSD.org/src/commit/?id=bec5167645b5d157a1c980099162362f115ccbfe commit bec5167645b5d157a1c980099162362f115ccbfe Author: Michal Meloun AuthorDate: 2024-11-03 12:15:33 +0000 Commit: Michal Meloun CommitDate: 2025-05-03 08:11:09 +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 Differential Revision: https://reviews.freebsd.org/D47488 (cherry picked from commit ba045ba49dedb068ba2f0e13fbb1c1a91fde8333) --- 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}