From: Jiaxun Yang <[email protected]>

For LoongArch, the start of the image is not the entry point. Refactor
the code base to allow entry point to be supplied by booti_setup().
Also update the kerneldoc comment for booti_setup() to reflect the
latest argument lists.

Link: 
https://www.kernel.org/doc/html/v7.2/arch/loongarch/booting.html#header-of-linux-loongarch-kernel-images
Signed-off-by: Jiaxun Yang <[email protected]>
Signed-off-by: Yao Zi <[email protected]>
---

Changed from v2
- Improve commit message, attach a link to documentation of LoongArch
  kernel image format
- Update kerneldoc comment for booti_setup()

Changed from v1
- Correct type of "entry" argument for RISC-V and sandbox

 arch/arm/lib/image.c     | 3 ++-
 arch/riscv/lib/image.c   | 4 +++-
 arch/sandbox/lib/bootm.c | 2 +-
 boot/bootm.c             | 5 +++--
 cmd/booti.c              | 5 +++--
 common/spl/spl.c         | 9 +++++----
 include/image.h          | 7 ++++---
 7 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/arch/arm/lib/image.c b/arch/arm/lib/image.c
index 2268661de93a..62c28b8310a5 100644
--- a/arch/arm/lib/image.c
+++ b/arch/arm/lib/image.c
@@ -29,7 +29,7 @@ struct Image_header {
 };
 
 int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
-               bool force_reloc)
+               ulong *entry, bool force_reloc)
 {
        struct Image_header *ih;
        uint64_t dst;
@@ -72,6 +72,7 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong 
*size,
                dst = gd->dram[0].start;
 
        *relocated_addr = ALIGN(dst, SZ_2M) + text_offset;
+       *entry = *relocated_addr;
 
        unmap_sysmem(ih);
 
diff --git a/arch/riscv/lib/image.c b/arch/riscv/lib/image.c
index a82f48e9a505..300be365ddfd 100644
--- a/arch/riscv/lib/image.c
+++ b/arch/riscv/lib/image.c
@@ -33,7 +33,7 @@ struct linux_image_h {
 };
 
 int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
-               bool force_reloc)
+               ulong *entry, bool force_reloc)
 {
        struct linux_image_h *lhdr;
 
@@ -56,6 +56,8 @@ int booti_setup(ulong image, ulong *relocated_addr, ulong 
*size,
                *relocated_addr = image;
        }
 
+       *entry = *relocated_addr;
+
        unmap_sysmem(lhdr);
 
        return 0;
diff --git a/arch/sandbox/lib/bootm.c b/arch/sandbox/lib/bootm.c
index 7a5f6f7d36ed..1a41c7c2735b 100644
--- a/arch/sandbox/lib/bootm.c
+++ b/arch/sandbox/lib/bootm.c
@@ -84,7 +84,7 @@ int do_bootm_linux(int flag, struct bootm_info *bmi)
 
 /* used for testing 'booti' command */
 int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
-               bool force_reloc)
+               ulong *entry, bool force_reloc)
 {
        log_err("Booting is not supported on the sandbox.\n");
 
diff --git a/boot/bootm.c b/boot/bootm.c
index 3bce85868346..2f92798f8320 100644
--- a/boot/bootm.c
+++ b/boot/bootm.c
@@ -723,9 +723,10 @@ static int bootm_load_os(struct bootm_headers *images, int 
boot_progress)
            images->os.os == IH_OS_LINUX) {
                ulong relocated_addr;
                ulong image_size;
+               ulong entry;
                int ret;
 
-               ret = booti_setup(load, &relocated_addr, &image_size, false);
+               ret = booti_setup(load, &relocated_addr, &image_size, &entry, 
false);
                if (ret) {
                        printf("Failed to prep arm64 kernel (err=%d)\n", ret);
                        return BOOTM_ERR_RESET;
@@ -739,7 +740,7 @@ static int bootm_load_os(struct bootm_headers *images, int 
boot_progress)
                        memmove((void *)relocated_addr, load_buf, image_size);
                }
 
-               images->ep = relocated_addr;
+               images->ep = entry;
                images->os.start = relocated_addr;
                images->os.end = relocated_addr + image_size;
        }
diff --git a/cmd/booti.c b/cmd/booti.c
index e6f67d6e1368..24c55ff92a27 100644
--- a/cmd/booti.c
+++ b/cmd/booti.c
@@ -27,6 +27,7 @@ static int booti_start(struct bootm_info *bmi)
        ulong ld;
        ulong relocated_addr;
        ulong image_size;
+       ulong entry;
        uint8_t *temp;
        ulong dest;
        ulong dest_end;
@@ -74,7 +75,7 @@ static int booti_start(struct bootm_info *bmi)
        }
        unmap_sysmem((void *)ld);
 
-       ret = booti_setup(ld, &relocated_addr, &image_size, false);
+       ret = booti_setup(ld, &relocated_addr, &image_size, &entry, false);
        if (ret)
                return 1;
 
@@ -85,7 +86,7 @@ static int booti_start(struct bootm_info *bmi)
                memmove((void *)relocated_addr, (void *)ld, image_size);
        }
 
-       images->ep = relocated_addr;
+       images->ep = entry;
        images->os.start = relocated_addr;
        images->os.end = relocated_addr + image_size;
 
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 6c9a1a1cbcc3..3856aafbca9a 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -115,7 +115,8 @@ int __weak bootz_setup(ulong image, ulong *start, ulong 
*end)
         return 1;
 }
 
-int __weak booti_setup(ulong image, ulong *relocated_addr, ulong *size, bool 
force_reloc)
+int __weak booti_setup(ulong image, ulong *relocated_addr, ulong *size,
+                      ulong *entry, bool force_reloc)
 {
         return 1;
 }
@@ -342,13 +343,13 @@ int spl_parse_image_header(struct spl_image_info 
*spl_image,
        }
 
        if (IS_ENABLED(CONFIG_SPL_OS_BOOT) && IS_ENABLED(CONFIG_SPL_BOOTI)) {
-               ulong start, size;
+               ulong start, size, entry;
 
-               if (!booti_setup((ulong)header, &start, &size, 0)) {
+               if (!booti_setup((ulong)header, &start, &size, &entry, 0)) {
                        spl_image->name = "Linux";
                        spl_image->os = IH_OS_LINUX;
                        spl_image->load_addr = start;
-                       spl_image->entry_point = start;
+                       spl_image->entry_point = entry;
                        spl_image->size = size;
                        debug(PHASE_PROMPT
                              "payload Image, load addr: 0x%lx size: %d\n",
diff --git a/include/image.h b/include/image.h
index 6edcb1995bfe..742e2b8cba7a 100644
--- a/include/image.h
+++ b/include/image.h
@@ -1126,16 +1126,17 @@ int image_setup_linux(struct bootm_headers *images);
 int bootz_setup(ulong image, ulong *start, ulong *end);
 
 /**
- * Return the correct start address and size of a Linux aarch64 Image.
+ * Return the correct start address and size of a Linux Image.
  *
  * @image: Address of image
- * @start: Returns start address of image
+ * @relocated_addr: Returns start address of image
  * @size : Returns size image
+ * @entry: Returns entry point of image
  * @force_reloc: Ignore image->ep field, always place image to RAM start
  * Return: 0 if OK, 1 if the image was not recognised
  */
 int booti_setup(ulong image, ulong *relocated_addr, ulong *size,
-               bool force_reloc);
+               ulong *entry, bool force_reloc);
 
 /*******************************************************************/
 /* New uImage format specific code (prefixed with fit_) */
-- 
2.55.0

Reply via email to