Skip to contentSkip to conversation

arm: let a defconfig ask for the Linux kernel image header

PATCH In review Aleksei Sviridkin 2 participants 7 messages Sep 20 – Sep 22

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 arm: let a defconfig ask for the Linux kernel image header

LINUX_KERNEL_IMAGE_HEADER has no prompt, so a board can only get the header through a select in its platform Kconfig, and the text offset base it needs has no prompt either, so a board cannot set it from its defconfig.

The header is what a stock boot loader that only ever starts a kernel image checks before it jumps, and a board whose stock loader cannot be replaced has to be chainloaded through it. The Keenetic KN-1012, an MT7981 router, is such a board: its loader accepts a kernel FIT and nothing else, and U-Boot runs from it as that kernel. Getting the header onto the binary took a platform Kconfig change for one board.

Give both symbols a prompt, so a board defconfig can enable the header and set the offset base the loader expects. Platforms that select the header are not affected, and the existing per-platform defaults for the offset base stay in force.

Assisted-by LLM
---
 arch/arm/Kconfig | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/arm/Kconfig +4 -3
index 3e9f3b5103..cc40be0048 100644
@@ -92,18 +92,19 @@ config SPL_USE_SEPARATE_FAULT_HANDLERS
 	  on them separately.
 
 config LINUX_KERNEL_IMAGE_HEADER
+	bool "Place a Linux kernel image header at the start of U-Boot"
 	depends on ARM64
-	bool
 	help
 	  Place a Linux kernel image header at the start of the U-Boot binary.
 	  The format of the header is described in the Linux kernel source at
 	  Documentation/arm64/booting.txt. This feature is useful since the
 	  image header reports the amount of memory (BSS and similar) that
-	  U-Boot needs to use, but which isn't part of the binary.
+	  U-Boot needs to use, but which isn't part of the binary. It also
+	  lets a boot loader that only starts kernel images chainload U-Boot.
 
 config LNX_KRNL_IMG_TEXT_OFFSET_BASE
+	hex "Base of the text offset in the Linux kernel image header"
 	depends on LINUX_KERNEL_IMAGE_HEADER
-	hex
 	help
 	  The value subtracted from CONFIG_TEXT_BASE to calculate the
 	  TEXT_OFFSET value written to the Linux kernel image header.
Signature · 1 line
2.53.0
#1 lore raw

PATCH 2/2 arm: mediatek: default the kernel image header text offset base

LNX_KRNL_IMG_TEXT_OFFSET_BASE has no default of its own, so enabling LINUX_KERNEL_IMAGE_HEADER on a MediaTek board leaves it empty and the link fails. mmp, rockchip and apple default it to TEXT_BASE, which gives a zero text_offset; do the same here. A board whose stock loader places the image at a fixed offset above its base sets the value in its defconfig instead. Found while chainloading U-Boot from the stock loader of the Keenetic KN-1012.

Assisted-by LLM
---
 arch/arm/mach-mediatek/Kconfig | 3 +++
 1 file changed, 3 insertions(+)
arch/arm/mach-mediatek/Kconfig +3 -0
index 5e6c50ca64..8e10e8c820 100644
@@ -215,4 +215,7 @@ config MTK_TZ_MOVABLE
 	select OF_SYSTEM_SETUP
 	bool
 
+config LNX_KRNL_IMG_TEXT_OFFSET_BASE
+	default TEXT_BASE
+
 endif
Signature · 1 line
2.53.0
#2 lore raw
In reply to Aleksei Sviridkin
Quoted 40 lines · Aleksei Sviridkin

LINUX_KERNEL_IMAGE_HEADER has no prompt, so a board can only get the header through a select in its platform Kconfig, and the text offset base it needs has no prompt either, so a board cannot set it from its defconfig.

The header is what a stock boot loader that only ever starts a kernel image checks before it jumps, and a board whose stock loader cannot be replaced has to be chainloaded through it. The Keenetic KN-1012, an MT7981 router, is such a board: its loader accepts a kernel FIT and nothing else, and U-Boot runs from it as that kernel. Getting the header onto the binary took a platform Kconfig change for one board.

Give both symbols a prompt, so a board defconfig can enable the header and set the offset base the loader expects. Platforms that select the header are not affected, and the existing per-platform defaults for the offset base stay in force.

Assisted-by LLM
---
 arch/arm/Kconfig | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
arch/arm/Kconfig +1 -2
index 3e9f3b5103..cc40be0048 100644
@@ -92,18 +92,19 @@ config SPL_USE_SEPARATE_FAULT_HANDLERS
 	  on them separately.
 
 config LINUX_KERNEL_IMAGE_HEADER
+	bool "Place a Linux kernel image header at the start of U-Boot"
 	depends on ARM64
-	bool
 	help
 	  Place a Linux kernel image header at the start of the U-Boot binary.
 	  The format of the header is described in the Linux kernel source at
 	  Documentation/arm64/booting.txt. This feature is useful since the
 	  image header reports the amount of memory (BSS and similar) that
-	  U-Boot needs to use, but which isn't part of the binary.

arch/arm/Kconfig config SPL_USE_SEPARATE_FAULT_HANDLERS · line 110

Quoted 10 lines
arch/arm/Kconfig +3 -1
+	  U-Boot needs to use, but which isn't part of the binary. It also
+	  lets a boot loader that only starts kernel images chainload U-Boot.
 
 config LNX_KRNL_IMG_TEXT_OFFSET_BASE
+	hex "Base of the text offset in the Linux kernel image header"
 	depends on LINUX_KERNEL_IMAGE_HEADER
-	hex
 	help
 	  The value subtracted from CONFIG_TEXT_BASE to calculate the
 	  TEXT_OFFSET value written to the Linux kernel image header.

This isn't a prompted option as boards that need it are expected to select it and provide the correct value.

Signature · 1 line
Tom
#3 lore raw

Dropping 1/2.

The board keeping me from the select is downstream: an MT7981 router whose U-Boot support lives in OpenWrt as a defconfig and a device tree, with no board directory here. I will carry a MediaTek-local pair of symbols there instead, one selecting the header and one holding the offset base, and leave the generic ones alone.

Does 2/2 still stand on its own? It gives mach-mediatek the same default TEXT_BASE for LNX_KRNL_IMG_TEXT_OFFSET_BASE that mach-mmp, mach-rockchip and mach-apple carry, so a MediaTek board that selects the header links without supplying its own. If you would rather every board spell out the value, I will drop that one too.

#4 lore raw
Quoted 8 lines · Aleksei Sviridkin

Dropping 1/2.

The board keeping me from the select is downstream: an MT7981 router whose U-Boot support lives in OpenWrt as a defconfig and a device tree, with no board directory here. I will carry a MediaTek-local pair of symbols there instead, one selecting the header and one holding the offset base, and leave the generic ones alone.

Quoted 5 lines

Does 2/2 still stand on its own? It gives mach-mediatek the same default TEXT_BASE for LNX_KRNL_IMG_TEXT_OFFSET_BASE that mach-mmp, mach-rockchip and mach-apple carry, so a MediaTek board that selects the header links without supplying its own. If you would rather every board spell out the value, I will drop that one too.

It's unclear to me, so it might be unclear to others, what the use case you're trying to solve here. These symbols are used for (typically) when we have some prior stage loader that assumes it's booting the linux kernel and we need to fake this enough to get loaded ourselves, instead.

Signature · 1 line
Tom
#5 lore raw
Quoted 4 lines · Tom Rini

It's unclear to me, so it might be unclear to others, what the use case you're trying to solve here. These symbols are used for (typically) when we have some prior stage loader that assumes it's booting the linux kernel and we need to fake this enough to get loaded ourselves, instead.

That is the case, yes. The board is a consumer router whose stock bootloader only ever starts an arm64 kernel image, so U-Boot carries the header and gets chainloaded as that image.

The offset is not zero here. TEXT_BASE is 0x41e00000 and the offset base is 0x41d80000, so text_offset comes out 0x80000, which is where the stock loader expects the image.

2/2 only adds the default the other machs already have. In arch/arm/Kconfig the symbol is a hex with no default, so a MediaTek board that selects the header does not build until it supplies a value. mmp, rockchip and apple each carry default TEXT_BASE.

#6 lore raw
Quoted 10 lines · Aleksei Sviridkin
Quoted 4 lines · Tom Rini

It's unclear to me, so it might be unclear to others, what the use case you're trying to solve here. These symbols are used for (typically) when we have some prior stage loader that assumes it's booting the linux kernel and we need to fake this enough to get loaded ourselves, instead.

That is the case, yes. The board is a consumer router whose stock bootloader only ever starts an arm64 kernel image, so U-Boot carries the header and gets chainloaded as that image.

Quoted 8 lines

The offset is not zero here. TEXT_BASE is 0x41e00000 and the offset base is 0x41d80000, so text_offset comes out 0x80000, which is where the stock loader expects the image.

2/2 only adds the default the other machs already have. In arch/arm/Kconfig the symbol is a hex with no default, so a MediaTek board that selects the header does not build until it supplies a value. mmp, rockchip and apple each carry default TEXT_BASE.

Then yes, a v2 where you just enable this for the platform that needs it should be fine, and please make sure to CC all of the mediatek maintainers, thanks.

Signature · 1 line
Tom