Skip to contentSkip to conversation

Nokia RX-51: Fix invalidating zImage kernel format

PATCH In review Pali Rohár 2 participants 10 messages Aug 11, 2022 – Aug 20, 2022

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

PATCH 1/5 Nokia RX-51: Fix invalidating zImage kernel format

Prior starting copy of kernel image to target location, invalidate also zImage magic header. This ensures that on target location would be image with valid header only in the case valid header was also in the source location and copy from source to target finished successfully. Copy is always skipped when kernel image in source location is invalid.

Add also comment to the code which explain what is the code doing.

Fixes cc434fccba4c ("Nokia RX-51: Add support for booting kernel in zImage format")
---
 board/nokia/rx51/lowlevel_init.S | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
board/nokia/rx51/lowlevel_init.S +4 -1
index 11c2cbef89a6..632595f83785 100644
@@ -72,7 +72,8 @@ copy_kernel_start:
 
 	/* remove header in target kernel */
 	mov	r5, #0
-	str	r5, [r3]
+	str	r5, [r3]	/* remove 4 bytes header of kernel uImage */
+	str	r5, [r3, #36]	/* remove 4 bytes header of kernel zImage */
 
 	/* check for valid kernel uImage */
 	ldr	r4, [r0]	/* r4 - 4 bytes header of kernel */
@@ -93,6 +94,8 @@ copy_kernel_loop:
 	bhi	copy_kernel_loop
 
 copy_kernel_end:
+
+	/* remove header in source kernel image */
 	mov	r5, #0
 	str	r5, [r0]	/* remove 4 bytes header of kernel uImage */
 	str	r5, [r0, #36]	/* remove 4 bytes header of kernel zImage */
Signature · 1 line
2.20.1
#7 lore raw

PATCH 5/5 Nokia RX-51: Move board required options from defconfig to Kconfig

Some of config options are board specific and should be set in into their default values automatically. So move them from defconfig file to Kconfig definitions to ensure that possible user custom defconfig files would have these required options also enabled.

---
 arch/arm/mach-omap2/omap3/Kconfig | 5 +++++
 board/nokia/rx51/Kconfig          | 6 ++++++
 configs/nokia_rx51_defconfig      | 7 -------
 3 files changed, 11 insertions(+), 7 deletions(-)
arch/arm/mach-omap2/omap3/Kconfig +5 -0
index 18574ab2b2ea..3e97ec262951 100644
@@ -108,6 +108,11 @@ config TARGET_OMAP3_LOGIC
 config TARGET_NOKIA_RX51
 	bool "Nokia RX51"
 	select POSITION_INDEPENDENT
+	select SKIP_LOWLEVEL_INIT
+	select SUPPORT_PASSING_ATAGS
+	select CMDLINE_TAG
+	select INITRD_TAG
+	select REVISION_TAG
 
 config TARGET_TAO3530
 	bool "TAO3530"
board/nokia/rx51/Kconfig +6 -0
index ec6a571a2263..7cf05077dad1 100644
@@ -1,5 +1,8 @@
 if TARGET_NOKIA_RX51
 
+config NR_DRAM_BANKS
+	default 2
+
 config SYS_BOARD
 	default "rx51"
 
@@ -9,4 +12,7 @@ config SYS_VENDOR
 config SYS_CONFIG_NAME
 	default "nokia_rx51"
 
+config SYS_PROMPT
+	default "Nokia RX-51 # "
+
 endif
configs/nokia_rx51_defconfig +0 -7
index 3365f7ae58df..4414ebc25e36 100644
@@ -1,16 +1,10 @@
 CONFIG_ARM=y
-CONFIG_SKIP_LOWLEVEL_INIT=y
 # CONFIG_SYS_THUMB_BUILD is not set
 CONFIG_SYS_L2CACHE_OFF=y
 CONFIG_ARCH_OMAP2PLUS=y
-CONFIG_SUPPORT_PASSING_ATAGS=y
-CONFIG_CMDLINE_TAG=y
-CONFIG_INITRD_TAG=y
-CONFIG_REVISION_TAG=y
 CONFIG_STATIC_MACH_TYPE=y
 CONFIG_MACH_TYPE=1955
 CONFIG_SYS_MALLOC_LEN=0xc0000
-CONFIG_NR_DRAM_BANKS=2
 CONFIG_TARGET_NOKIA_RX51=y
 CONFIG_SYS_LOAD_ADDR=0x80000000
 CONFIG_OPTIMIZE_INLINING=y
@@ -26,7 +20,6 @@ CONFIG_USE_PREBOOT=y
 CONFIG_PREBOOT="run preboot"
 # CONFIG_SYS_DEVICE_NULLDEV is not set
 CONFIG_HUSH_PARSER=y
-CONFIG_SYS_PROMPT="Nokia RX-51 # "
 # CONFIG_CMD_BDI is not set
 CONFIG_CMD_BOOTZ=y
 # CONFIG_BOOTM_NETBSD is not set
Signature · 1 line
2.20.1
#5 lore raw

PATCH 4/5 Nokia RX-51: Simplify calculation of attached kernel image address

In reply to Pali Rohár

Now when board starup code does not copy image to CONFIG_SYS_TEXT_BASE address there is no need to calculate all addresses from base address at runtime. The only address which needs to be calculated is attached kernel image address which can be simplified at compile time without need to know CONFIG_SYS_TEXT_BASE address or relocation address at the runtime.

---
 board/nokia/rx51/lowlevel_init.S | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)
board/nokia/rx51/lowlevel_init.S +4 -17
index 4f76e80b20f1..c1785bc3f72f 100644
@@ -6,11 +6,8 @@
 
 #include <config.h>
 
-relocaddr:		/* address of this relocaddr section after coping */
-	.word .		/* address of section (calculated at compile time) */
-
-startaddr:		/* address of u-boot after copying */
-	.word CONFIG_SYS_TEXT_BASE
+kernoffs:		/* offset of kernel image from this address */
+	.word KERNEL_OFFSET - (. - CONFIG_SYS_TEXT_BASE)
 
 kernaddr:		/* address of kernel after copying */
 	.word KERNEL_ADDRESS
@@ -18,9 +15,6 @@ kernaddr:		/* address of kernel after copying */
 kernsize:		/* maximal size of kernel image */
 	.word KERNEL_MAXSIZE
 
-kernoffs:		/* offset of kernel image in loaded u-boot */
-	.word KERNEL_OFFSET
-
 imagesize:		/* maximal size of image */
 	.word IMAGE_MAXSIZE
 
@@ -53,16 +47,9 @@ save_boot_params:
  */
 
 copy_kernel_start:
-	adr	r0, relocaddr	/* r0 - address of section relocaddr */
-	ldr	r1, relocaddr	/* r1 - address of relocaddr after relocation */
-
-	/* r4 - calculated offset */
-	sub	r4, r0, r1
-
 	/* r0 - start of kernel before */
-	ldr	r0, startaddr
-	add	r0, r0, r4
-	ldr	r1, kernoffs
+	adr	r0, kernoffs	/* r0 - current address of kernoffs section */
+	ldr	r1, kernoffs	/* r1 - offset of kernel image from kernoffs section */
 	add	r0, r0, r1
 
 	/* r3 - start of kernel after */
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/5 Nokia RX-51: Use U-Boot generic position independent code

In reply to Pali Rohár

Switch from custom board specific fixup/copy code to U-Boot generic position independent code provided by config option POSITION_INDEPENDENT.

This also slightly decrease size of u-boot.bin binary (by 52 bytes). Note that option POSITION_INDEPENDENT increase size but not more than custom board fixup/copy code which is being deleted (as it is not needed anymore).

---
 arch/arm/mach-omap2/omap3/Kconfig |   1 +
 board/nokia/rx51/lowlevel_init.S  | 127 ++++--------------------------
 configs/nokia_rx51_defconfig      |   1 -
 3 files changed, 16 insertions(+), 113 deletions(-)
arch/arm/mach-omap2/omap3/Kconfig +1 -0
index 81c898b66e34..18574ab2b2ea 100644
@@ -107,6 +107,7 @@ config TARGET_OMAP3_LOGIC
 
 config TARGET_NOKIA_RX51
 	bool "Nokia RX51"
+	select POSITION_INDEPENDENT
 
 config TARGET_TAO3530
 	bool "TAO3530"
board/nokia/rx51/lowlevel_init.S +15 -112

141 lines not on this page · raw message

configs/nokia_rx51_defconfig +0 -1
index 309cf28269c1..3365f7ae58df 100644
@@ -9,7 +9,6 @@ CONFIG_INITRD_TAG=y
 CONFIG_REVISION_TAG=y
 CONFIG_STATIC_MACH_TYPE=y
 CONFIG_MACH_TYPE=1955
-CONFIG_SYS_TEXT_BASE=0x80008000
 CONFIG_SYS_MALLOC_LEN=0xc0000
 CONFIG_NR_DRAM_BANKS=2
 CONFIG_TARGET_NOKIA_RX51=y
Signature · 1 line
2.20.1
#3 lore raw

PATCH 3/5 Nokia RX-51: Simplify copy kernel code

In reply to Pali Rohár

Expression (r + (r0 - r1)) produce same result as (r - (r1 - r0)). So it does not matter which one is called. Always call the first option and remove second one.

---
 board/nokia/rx51/lowlevel_init.S | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
board/nokia/rx51/lowlevel_init.S +2 -5
index dd3c830cc2e2..4f76e80b20f1 100644
@@ -55,16 +55,13 @@ save_boot_params:
 copy_kernel_start:
 	adr	r0, relocaddr	/* r0 - address of section relocaddr */
 	ldr	r1, relocaddr	/* r1 - address of relocaddr after relocation */
-	cmp	r0, r1
 
 	/* r4 - calculated offset */
-	subhi	r4, r0, r1
-	sublo	r4, r1, r0
+	sub	r4, r0, r1
 
 	/* r0 - start of kernel before */
 	ldr	r0, startaddr
-	addhi	r0, r0, r4
-	sublo	r0, r0, r4
+	add	r0, r0, r4
 	ldr	r1, kernoffs
 	add	r0, r0, r1
 
Signature · 1 line
2.20.1
#9 lore raw
In reply to Pali Rohár
Quoted 10 lines · Pali Rohár

Prior starting copy of kernel image to target location, invalidate also zImage magic header. This ensures that on target location would be image with valid header only in the case valid header was also in the source location and copy from source to target finished successfully. Copy is always skipped when kernel image in source location is invalid.

Add also comment to the code which explain what is the code doing.

Fixes cc434fccba4c ("Nokia RX-51: Add support for booting kernel in zImage format")

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#2 lore raw

Re: [PATCH 2/5] Nokia RX-51: Use U-Boot generic position independent code

In reply to Pali Rohár
Quoted 8 lines · Pali Rohár

Switch from custom board specific fixup/copy code to U-Boot generic position independent code provided by config option POSITION_INDEPENDENT.

This also slightly decrease size of u-boot.bin binary (by 52 bytes). Note that option POSITION_INDEPENDENT increase size but not more than custom board fixup/copy code which is being deleted (as it is not needed anymore).

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#4 lore raw

Re: [PATCH 3/5] Nokia RX-51: Simplify copy kernel code

In reply to Pali Rohár
Quoted 5 lines · Pali Rohár

Expression (r + (r0 - r1)) produce same result as (r - (r1 - r0)). So it does not matter which one is called. Always call the first option and remove second one.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#6 lore raw

Re: [PATCH 4/5] Nokia RX-51: Simplify calculation of attached kernel image address

In reply to Pali Rohár
Quoted 7 lines · Pali Rohár

Now when board starup code does not copy image to CONFIG_SYS_TEXT_BASE address there is no need to calculate all addresses from base address at runtime. The only address which needs to be calculated is attached kernel image address which can be simplified at compile time without need to know CONFIG_SYS_TEXT_BASE address or relocation address at the runtime.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#8 lore raw

Re: [PATCH 5/5] Nokia RX-51: Move board required options from defconfig to Kconfig

In reply to Pali Rohár
Quoted 6 lines · Pali Rohár

Some of config options are board specific and should be set in into their default values automatically. So move them from defconfig file to Kconfig definitions to ensure that possible user custom defconfig files would have these required options also enabled.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom