From nobody Sat Nov 09 07:16:31 2024 X-Original-To: dev-commits-src-main@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 4XlnDH6WvMz5dRqb; Sat, 09 Nov 2024 07:16:31 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XlnDH5rkMz4RFx; Sat, 9 Nov 2024 07:16:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731136591; 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=DeaQhYivflgcKXgRItmV6oR/pwdezpEUFwkykSP687k=; b=FTwDg8P0F2vvXm8/K/fCGj8czx2GaizK8XgvFCMahp1YC/23bl8SACWcrFfTfrNetUbH3k hYCoOHj0rct0xrN+7m+DQqoHgk2unx3M8g/Gy/h6CUQq4E4MFDs+XOajXdzK0dW5Cf3apw /NvesxdEhmdmmkYeIwJuog57CbeJO7jiHqnsYg+EKZngKVjrrO17q6yrKchRXatK9LZVE/ GbpyUNun2/eEZWOmuRk8tZjV02iln9hEdXVjpGN/PaI5LPhHWJZqMocnZ/hD23D9P4dib5 I0aydE/LITiByext+qT/8SkLOs7A4w9uihkrJzl1JGWVBZLlbXwnqHngGAs7sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1731136591; 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=DeaQhYivflgcKXgRItmV6oR/pwdezpEUFwkykSP687k=; b=qimlZTA8sZZwFsJPycgfH0aiygNEuYujauaknVAyQxZO/q5iZIa/tQTJxypRYXSGBeycDI AavhHistuWaJszHhFzC4K1520Wq5qOSqPopOytCX/JatWu3ifXlTjvoJaWhrvYOwIbYPXL D5kW1nuVoXR4k187iy9a8CMq3wBZl8w5x8vFd1TtrtG3ixSce5A3Z9rM6e8HuSCpmDMrXl i8EOcxA1+jitVdC00UiJERept2ZBM2Yjhi3F9+8XxVEOHBprv9x1z1OPLDTxRUhHpx921U eJNDnRmlbVIbX0DwCLhqlmiG1Xz/RuSOg39lqrLaKMlR+1YbKHxS+tKwMu2GSQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1731136591; a=rsa-sha256; cv=none; b=j1WwwaS8nd8mBtA1XtmzzWTueWBCtIrWwUfAPjHzo9sj9ogj+NL4GWv1v3uHeuI2h5fOPB jot3X4d+JDUvQ9Jsd75kXp1hRKkLpXDaSvwMg+QRkPTtq8Xp3L2O871l+fZksHGYiPRc/H n0RkMm4y1TOnmdCEOOKjRGfQr0Z5WuoglEfawEiYMSqlZUBSGWtEVJVkduS9tVm21nI5LR 3Ht+SHiew1FLWkBmRXBgP4XNxYsAng/p5pKGa/zm5lZjAxFLLTg64+VR6ftFzpUs/U7uNI akgPmSR7J5oiwve3El0s334eUBVgMI5pS2Z/q9/r2kB8fC4jK2iQlGSeHTjh/g== 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 4XlnDH5BP5z14Jm; Sat, 9 Nov 2024 07:16:31 +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 4A97GVCk087310; Sat, 9 Nov 2024 07:16:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A97GVDt087307; Sat, 9 Nov 2024 07:16:31 GMT (envelope-from git) Date: Sat, 9 Nov 2024 07:16:31 GMT Message-Id: <202411090716.4A97GVDt087307@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Michal Meloun Subject: git: ba045ba49ded - main - arm: Improve the creation of kernel.bin List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: ba045ba49dedb068ba2f0e13fbb1c1a91fde8333 Auto-Submitted: auto-generated The branch main has been updated by mmel: URL: https://cgit.FreeBSD.org/src/commit/?id=ba045ba49dedb068ba2f0e13fbb1c1a91fde8333 commit ba045ba49dedb068ba2f0e13fbb1c1a91fde8333 Author: Michal Meloun AuthorDate: 2024-11-03 12:15:33 +0000 Commit: Michal Meloun CommitDate: 2024-11-09 07:15:23 +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 --- sys/conf/Makefile.arm | 36 ++++++++++++++++++++---------------- sys/conf/Makefile.arm64 | 1 + 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/sys/conf/Makefile.arm b/sys/conf/Makefile.arm index 5416aff76666..8e98e5b07648 100644 --- a/sys/conf/Makefile.arm +++ b/sys/conf/Makefile.arm @@ -57,6 +57,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) \ @@ -64,22 +65,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_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 @@ -98,3 +83,22 @@ genassym.o: bus_if.h device_if.h %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 52f0f9052db3..ed9624ee5446 100644 --- a/sys/conf/Makefile.arm64 +++ b/sys/conf/Makefile.arm64 @@ -88,6 +88,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}