From nobody Mon May 5 07:03:08 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 4ZrXY90Gq2z5v2LR; Mon, 05 May 2025 07:03:09 +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 4ZrXY86FjFz3D4h; Mon, 05 May 2025 07:03:08 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746428588; 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=NpQlLgEDFuIkBgk3y/KMdvLn+KfoTXTO8uqINcAfIt0=; b=dGEMBSob3GjsIgKRFJLumdxrWpX8Ra5rclY8ym8IO/db+BTfDS5RC9497LTqAHHjii3Q3H 3c9ys9xzhpd/f4CWKOFKA9V7hyBzZMjbFIXVUYG6OmiLcvj9Z1fdx4NC2LlAIbPG53UDxc lVQe4dZsfcpKzF6MGyPbPgdvSalrsWVIarvhwR5B8qIw/lAX6fJveYXBGXbSk+C3geiT0P qdT94nYzGhG7+9nxuYqIYSGgaUqAfqCyKlHlcFghp3Fu6gjKa7Cqz2w0E5n5OHLd1l1NH8 N9Bq2zeoG3TdB3IJvAYLfdSa6CiKeAqKrY0UGisvA6n1qXqnyniNF5KaJTQXpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1746428588; 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=NpQlLgEDFuIkBgk3y/KMdvLn+KfoTXTO8uqINcAfIt0=; b=oQdy9kOQjsHF1RYBO+iFb6kQiWNLd2y/Ywav+gblyJvMAbqs4s3OAcAa+NLTzlw0uRwYVF IhkgzKW3Qr3vfkV0/mAv5GmisVNGTCaE6DcX/7pbj5zEK73CrR3V2gtzngK7KsiYSMC7tD C+pwaJ32Ua7ADpARo1Pt0TCD8wniEOL7N7lCASSNiehxW/NJ9b8a2QxbGLj053UQ0Lj6vQ FOxquDIRrjWQ4M89oXvoH6JYvsMehKF9AriilrpotamhzV4U7STlNH4Yr9GulJ0YQfFitO 2JCHz3vdktMwZVQ3dufHyv/J5LIx6tZflWTbKQxBsEugsHtfDdQFJcL9wqEeSQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1746428588; a=rsa-sha256; cv=none; b=TEgiGtp2qbWyBvBP0sRN/LHzrFmk28YAJo0P7Xf3Rjd6EVVNIXK87rKZTzb2gWrDCnkuvE 5yAygep49swICo3+JNE8HpDOrsIkfXc4dIMmrSYM/koiQo8iT1AzQGtYj1BOuAgQb5fz4u hGQW061MtV+Vr16kf0nQHNdudeCj1YF8KEYNDaxHDw/jsIFfFgXbBUeB+jnRJbg5Cgtint GKF0nNzbue3qfw8ufRSjqzRYy0awekUI47dMacqK0herxBpKyIy5n8T8SYvvzIHadRc9I4 E7c5DKuuSVLnYQMm2SnKVYK2WEtV8yZHWi34y7AB3laf1cl6u33YhNI096e/Sw== 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 4ZrXY85lGDz13hp; Mon, 05 May 2025 07:03:08 +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 545738rF036987; Mon, 5 May 2025 07:03:08 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 545738gj036984; Mon, 5 May 2025 07:03:08 GMT (envelope-from git) Date: Mon, 5 May 2025 07:03:08 GMT Message-Id: <202505050703.545738gj036984@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Colin Percival Subject: git: 95d87d5f5655 - releng/14.3 - 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: cperciva X-Git-Repository: src X-Git-Refname: refs/heads/releng/14.3 X-Git-Reftype: branch X-Git-Commit: 95d87d5f5655008def3f7658820ee7dd6191236f Auto-Submitted: auto-generated The branch releng/14.3 has been updated by cperciva: URL: https://cgit.FreeBSD.org/src/commit/?id=95d87d5f5655008def3f7658820ee7dd6191236f commit 95d87d5f5655008def3f7658820ee7dd6191236f Author: Michal Meloun AuthorDate: 2024-11-03 12:15:33 +0000 Commit: Colin Percival 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}