command: Remove the cmd_tbl_t typedef
[oweals/u-boot.git] / arch / mips / lib / bootm.c
index 0c6a4ab3b329ba10d889384463acc23e5d75e1d9..cbc4413d5dade00c4b04ee5d9737990d413701df 100644 (file)
@@ -1,13 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2003
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
+#include <bootstage.h>
+#include <env.h>
 #include <image.h>
 #include <fdt_support.h>
+#include <lmb.h>
 #include <asm/addrspace.h>
 #include <asm/io.h>
 
@@ -42,7 +44,7 @@ void arch_lmb_reserve(struct lmb *lmb)
 
        /* adjust sp by 4K to be safe */
        sp -= 4096;
-       lmb_reserve(lmb, sp, CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp);
+       lmb_reserve(lmb, sp, gd->ram_top - sp);
 }
 
 static void linux_cmdline_init(void)
@@ -80,7 +82,7 @@ static void linux_cmdline_legacy(bootm_headers_t *images)
 
        linux_cmdline_init();
 
-       bootargs = getenv("bootargs");
+       bootargs = env_get("bootargs");
        if (!bootargs)
                return;
 
@@ -202,11 +204,11 @@ static void linux_env_legacy(bootm_headers_t *images)
        sprintf(env_buf, "0x%X", (uint) (gd->bd->bi_flashsize));
        linux_env_set("flash_size", env_buf);
 
-       cp = getenv("ethaddr");
+       cp = env_get("ethaddr");
        if (cp)
                linux_env_set("ethaddr", cp);
 
-       cp = getenv("eth1addr");
+       cp = env_get("eth1addr");
        if (cp)
                linux_env_set("eth1addr", cp);
 
@@ -216,23 +218,6 @@ static void linux_env_legacy(bootm_headers_t *images)
        }
 }
 
-static int boot_reloc_ramdisk(bootm_headers_t *images)
-{
-       ulong rd_len = images->rd_end - images->rd_start;
-
-       /*
-        * In case of legacy uImage's, relocation of ramdisk is already done
-        * by do_bootm_states() and should not repeated in 'bootm prep'.
-        */
-       if (images->state & BOOTM_STATE_RAMDISK) {
-               debug("## Ramdisk already relocated\n");
-               return 0;
-       }
-
-       return boot_ramdisk_high(&images->lmb, images->rd_start,
-               rd_len, &images->initrd_start, &images->initrd_end);
-}
-
 static int boot_reloc_fdt(bootm_headers_t *images)
 {
        /*
@@ -253,45 +238,41 @@ static int boot_reloc_fdt(bootm_headers_t *images)
 #endif
 }
 
-#ifdef CONFIG_ARCH_FIXUP_FDT
+#if CONFIG_IS_ENABLED(MIPS_BOOT_FDT) && CONFIG_IS_ENABLED(OF_LIBFDT)
 int arch_fixup_fdt(void *blob)
 {
-#if CONFIG_IS_ENABLED(MIPS_BOOT_FDT) && CONFIG_IS_ENABLED(OF_LIBFDT)
        u64 mem_start = virt_to_phys((void *)gd->bd->bi_memstart);
        u64 mem_size = gd->ram_size;
 
        return fdt_fixup_memory_banks(blob, &mem_start, &mem_size, 1);
-#else
-       return 0;
-#endif
 }
 #endif
 
 static int boot_setup_fdt(bootm_headers_t *images)
 {
+       images->initrd_start = virt_to_phys((void *)images->initrd_start);
+       images->initrd_end = virt_to_phys((void *)images->initrd_end);
        return image_setup_libfdt(images, images->ft_addr, images->ft_len,
                &images->lmb);
 }
 
 static void boot_prep_linux(bootm_headers_t *images)
 {
-       boot_reloc_ramdisk(images);
-
        if (CONFIG_IS_ENABLED(MIPS_BOOT_FDT) && images->ft_len) {
                boot_reloc_fdt(images);
                boot_setup_fdt(images);
        } else {
-               if (CONFIG_IS_ENABLED(CONFIG_MIPS_BOOT_ENV_LEGACY))
-                       linux_env_legacy(images);
-
                if (CONFIG_IS_ENABLED(MIPS_BOOT_CMDLINE_LEGACY)) {
                        linux_cmdline_legacy(images);
 
-                       if (!CONFIG_IS_ENABLED(CONFIG_MIPS_BOOT_ENV_LEGACY))
+                       if (!CONFIG_IS_ENABLED(MIPS_BOOT_ENV_LEGACY))
                                linux_cmdline_append(images);
 
                        linux_cmdline_dump();
                }
+
+               if (CONFIG_IS_ENABLED(MIPS_BOOT_ENV_LEGACY))
+                       linux_env_legacy(images);
        }
 }
 
@@ -315,6 +296,9 @@ static void boot_jump_linux(bootm_headers_t *images)
        bootstage_report();
 #endif
 
+       if (CONFIG_IS_ENABLED(RESTORE_EXCEPTION_VECTOR_BASE))
+               trap_restore();
+
        if (images->ft_len)
                kernel(-2, (ulong)images->ft_addr, 0, 0);
        else
@@ -322,8 +306,8 @@ static void boot_jump_linux(bootm_headers_t *images)
                        linux_extra);
 }
 
-int do_bootm_linux(int flag, int argc, char * const argv[],
-                       bootm_headers_t *images)
+int do_bootm_linux(int flag, int argc, char *const argv[],
+                  bootm_headers_t *images)
 {
        /* No need for those on MIPS */
        if (flag & BOOTM_STATE_OS_BD_T)