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

2021-07-15 Thread Lokesh Vutla
On Fri, 18 Jun 2021 15:27:03 +0200, Pali Rohár wrote:
> 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


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

2021-06-18 Thread 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.

Signed-off-by: Pali Rohár 
---
 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(-)

diff --git a/board/nokia/rx51/lowlevel_init.S b/board/nokia/rx51/lowlevel_init.S
index 1466d976fc4b..11c2cbef89a6 100644
--- a/board/nokia/rx51/lowlevel_init.S
+++ b/board/nokia/rx51/lowlevel_init.S
@@ -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 */
diff --git a/configs/nokia_rx51_defconfig b/configs/nokia_rx51_defconfig
index 061f5c357c46..981e6f95cb1f 100644
--- a/configs/nokia_rx51_defconfig
+++ b/configs/nokia_rx51_defconfig
@@ -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
diff --git a/doc/README.nokia_rx51 b/doc/README.nokia_rx51
index 84d1912ddd2b..7f22ed49bd75 100644
--- a/doc/README.nokia_rx51
+++ b/doc/README.nokia_rx51
@@ -11,13 +11,14 @@ a kernel. In order to transparently boot the original 
kernel, it will be
 appended to u-boot.bin at 0x4. 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
 
diff --git a/include/configs/nokia_rx51.h b/include/configs/nokia_rx51.h
index fe991ea03991..742c1a646545 100644
--- a/include/configs/nokia_rx51.h
+++ b/include/configs/nokia_rx51.h
@@ -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