Skip to contentSkip to conversation

Nokia RX-51: Add support for booting kernel in zImage format

PATCH In review Pali Rohár 2 participants 3 messages Jun 18, 2021 – Jul 15, 2021 Arm/actions semi architecture

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 Nokia RX-51: Add support for booting kernel in zImage format

Enable U-Boot bootz command and update env scripts to try loading also zImage file and to try booting via bootz command.

Update also lowlevel_init.S code for checking validity of zImage magic to correctly relocate kernel in zImage format.

This change allows U-Boot to directly boot Linux kernel without need for converting kernel image into U-Boot uImage format.

---
 board/nokia/rx51/lowlevel_init.S | 12 ++++-
 configs/nokia_rx51_defconfig     |  1 +
 doc/README.nokia_rx51            | 10 +++--
 include/configs/nokia_rx51.h     | 11 +++--
 test/nokia_rx51_test.sh          | 76 +++++++++++++++++++++++++++-----
 5 files changed, 91 insertions(+), 19 deletions(-)
board/nokia/rx51/lowlevel_init.S +11 -1
index 1466d976fc4b..11c2cbef89a6 100644
@@ -27,6 +27,9 @@ imagesize:		/* maximal size of image */
 ih_magic:		/* IH_MAGIC in big endian from include/image.h */
 	.word 0x56190527
 
+z_magic:		/* LINUX_ARM_ZIMAGE_MAGIC */
+	.word 0x016f2818
+
 /*
  * Routine: save_boot_params (called after reset from start.S)
  * Description: Copy attached kernel to address KERNEL_ADDRESS
@@ -75,6 +78,12 @@ copy_kernel_start:
 	ldr	r4, [r0]	/* r4 - 4 bytes header of kernel */
 	ldr	r5, ih_magic	/* r5 - IH_MAGIC */
 	cmp	r4, r5
+	beq	copy_kernel_loop
+
+	/* check for valid kernel zImage */
+	ldr	r4, [r0, #36]	/* r4 - 4 bytes header of kernel at offset 36 */
+	ldr	r5, z_magic	/* r5 - LINUX_ARM_ZIMAGE_MAGIC */
+	cmp	r4, r5
 	bne	copy_kernel_end	/* skip if invalid image */
 
 copy_kernel_loop:
@@ -85,7 +94,8 @@ copy_kernel_loop:
 
 copy_kernel_end:
 	mov	r5, #0
-	str	r5, [r0]	/* remove 4 bytes header of kernel */
+	str	r5, [r0]	/* remove 4 bytes header of kernel uImage */
+	str	r5, [r0, #36]	/* remove 4 bytes header of kernel zImage */
 
 
 /* Fix u-boot code */
configs/nokia_rx51_defconfig +1 -0
index 061f5c357c46..981e6f95cb1f 100644
@@ -18,6 +18,7 @@ CONFIG_CONSOLE_MUX=y
 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
 # CONFIG_BOOTM_PLAN9 is not set
 # CONFIG_BOOTM_RTEMS is not set
doc/README.nokia_rx51 +6 -4
index 84d1912ddd2b..7f22ed49bd75 100644
@@ -11,13 +11,14 @@ a kernel. In order to transparently boot the original kernel, it will be
 appended to u-boot.bin at 0x40000. NOLO will load the entire image into
 (random) memory and execute u-boot, which saves hw revision, boot reason
 and boot mode ATAGs set by NOLO. Then the bootscripts will attempt to load
-uImage or boot.scr from a fat, ext2/ext3 or ext4 filesystem in external
+uImage, zImage or boot.scr from a fat or ext2/3/4 filesystem on external
 SD card or internal eMMC memory. If this fails or keyboard is closed then
 the appended kernel image will be booted using some generated and some
 stored ATAGs (see boot order).
 
-For generating combined image of u-boot and kernel there is a simple script
-called u-boot-gen-combined. It is available in following repository:
+For generating combined image of u-boot and kernel (either in uImage or zImage
+format) there is a simple script called u-boot-gen-combined. It is available in
+following repository:
 
   https://github.com/pali/u-boot-maemo
 
@@ -41,7 +42,8 @@ Boot from SD or eMMC in this order:
  * 1.
    * 1.1 find boot.scr on first fat partition
    * 1.2 find uImage on first fat partition
-   * 1.3 same order for 2. - 4. fat partition
+   * 1.3 find zImage on first fat partition
+   * 1.4 same order for 2. - 4. fat partition
  * 2. same as 1. but for ext2/3 partition
  * 3. same as 1. but for ext4 partition
 
include/configs/nokia_rx51.h +7 -4
index fe991ea03991..742c1a646545 100644
@@ -129,12 +129,14 @@ int rx51_kp_getc(struct stdio_dev *sdev);
 	"scriptboot=echo Running ${mmcscriptfile} from mmc " \
 		"${mmcnum}:${mmcpart} ...; source ${scriptaddr}\0" \
 	"kernboot=echo Booting ${mmckernfile} from mmc " \
-		"${mmcnum}:${mmcpart} ...; bootm ${kernaddr}\0" \
+		"${mmcnum}:${mmcpart} ...; bootm ${kernaddr} || " \
+			"bootz ${kernaddr}\0" \
 	"kerninitrdboot=echo Booting ${mmckernfile} ${mmcinitrdfile} from mmc "\
-		"${mmcnum}:${mmcpart} ...; bootm ${kernaddr} ${initrdaddr}\0" \
+		"${mmcnum}:${mmcpart} ...; bootm ${kernaddr} ${initrdaddr} || " \
+			"bootz ${kernaddr} ${initrdaddr}\0" \
 	"attachboot=echo Booting attached kernel image ...;" \
 		"setenv setup_omap_atag 1;" \
-		"bootm ${attkernaddr};" \
+		"bootm ${attkernaddr} || bootz ${attkernaddr};" \
 		"setenv setup_omap_atag\0" \
 	"trymmcscriptboot=if run switchmmc; then " \
 			"if run scriptload; then " \
@@ -154,7 +156,8 @@ int rx51_kp_getc(struct stdio_dev *sdev);
 			"fi; " \
 		"fi\0" \
 	"trymmcpartboot=setenv mmcscriptfile boot.scr; run trymmcscriptboot;" \
-		"setenv mmckernfile uImage; run trymmckernboot\0" \
+		"setenv mmckernfile uImage; run trymmckernboot;" \
+		"setenv mmckernfile zImage; run trymmckernboot\0" \
 	"trymmcallpartboot=setenv mmcpart 1; run trymmcpartboot;" \
 		"setenv mmcpart 2; run trymmcpartboot;" \
 		"setenv mmcpart 3; run trymmcpartboot;" \
test/nokia_rx51_test.sh +66 -10

146 lines not on this page · raw message

Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/2 Nokia RX-51: Load bootmenu also from uSD card

By default bootmenu is loaded only from eMMC. After this change U-Boot first tries to load bootmenu from uSD card and if it fails then fallback to eMMC. People want to boot alternative OS from removable uSD without need to modify eMMC content. So this backward compatible change allows it.

Part of this change is also optimization of trymmc* macros so they can be used in preboot macro for loading bootmenu.

---
 include/configs/nokia_rx51.h | 35 +++++++++--------------------------
 1 file changed, 9 insertions(+), 26 deletions(-)
include/configs/nokia_rx51.h +9 -26
index 742c1a646545..7ef25ea8389c 100644
@@ -138,23 +138,10 @@ int rx51_kp_getc(struct stdio_dev *sdev);
 		"setenv setup_omap_atag 1;" \
 		"bootm ${attkernaddr} || bootz ${attkernaddr};" \
 		"setenv setup_omap_atag\0" \
-	"trymmcscriptboot=if run switchmmc; then " \
-			"if run scriptload; then " \
-				"run scriptboot;" \
-			"fi;" \
-		"fi\0" \
-	"trymmckernboot=if run switchmmc; then " \
-			"if run kernload; then " \
-				"run kernboot;" \
-			"fi;" \
-		"fi\0" \
-	"trymmckerninitrdboot=if run switchmmc; then " \
-			"if run initrdload; then " \
-				"if run kernload; then " \
-					"run kerninitrdboot;" \
-				"fi;" \
-			"fi; " \
-		"fi\0" \
+	"trymmcscriptboot=run switchmmc && run scriptload && run scriptboot\0" \
+	"trymmckernboot=run switchmmc && run kernload && run kernboot\0" \
+	"trymmckerninitrdboot=run switchmmc && run initrdload && " \
+		"run kernload && run kerninitrdboot\0" \
 	"trymmcpartboot=setenv mmcscriptfile boot.scr; run trymmcscriptboot;" \
 		"setenv mmckernfile uImage; run trymmckernboot;" \
 		"setenv mmckernfile zImage; run trymmckernboot\0" \
@@ -170,15 +157,11 @@ int rx51_kp_getc(struct stdio_dev *sdev);
 		"fi\0" \
 	"emmcboot=setenv mmcnum 1; run trymmcboot\0" \
 	"sdboot=setenv mmcnum 0; run trymmcboot\0" \
-	"preboot=setenv mmcnum 1; setenv mmcpart 1;" \
-		"setenv mmcscriptfile bootmenu.scr;" \
-		"if run switchmmc; then " \
-			"setenv mmctype fat;" \
-			"if run scriptload; then run scriptboot; else " \
-				"setenv mmctype ext4;" \
-				"if run scriptload; then run scriptboot; fi;" \
-			"fi;" \
-		"fi;" \
+	"trymmcbootmenu=setenv mmctype fat && run trymmcscriptboot || " \
+		"setenv mmctype ext4 && run trymmcscriptboot\0" \
+	"preboot=setenv mmcpart 1; setenv mmcscriptfile bootmenu.scr;" \
+		"setenv mmcnum 0 && run trymmcbootmenu || " \
+		"setenv mmcnum 1 && run trymmcbootmenu;" \
 		"if run slide; then true; else " \
 			"setenv bootmenu_delay 0;" \
 			"setenv bootdelay 0;" \
Signature · 1 line
2.20.1
#2 lore raw
In reply to Pali Rohár
Quoted 8 lines · Pali Rohár

Enable U-Boot bootz command and update env scripts to try loading also zImage file and to try booting via bootz command.

Update also lowlevel_init.S code for checking validity of zImage magic to correctly relocate kernel in zImage format.

This change allows U-Boot to directly boot Linux kernel without need for converting kernel image into U-Boot uImage format.

Applied to https://source.denx.de/u-boot/custodians/u-boot-ti.git for-rc, thanks! [1/2] Nokia RX-51: Add support for booting kernel in zImage format

      https://source.denx.de/u-boot/custodians/u-boot-ti/-/commit/77122d6fad
[2/2] Nokia RX-51: Load bootmenu also from uSD card
      https://source.denx.de/u-boot/custodians/u-boot-ti/-/commit/da523d3250

--
Thanks and Regards,
Lokesh