]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - common/spl/spl.c
SPL: Add support for loading image from ram in SPL.
[karo-tx-uboot.git] / common / spl / spl.c
index 70c374a49071ccaf1046a2ce50e031962fd21eb9..c640f874040b9f118ca44e30c8f3936379cce6b2 100644 (file)
@@ -35,6 +35,9 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#ifndef CONFIG_SYS_UBOOT_START
+#define CONFIG_SYS_UBOOT_START CONFIG_SYS_TEXT_BASE
+#endif
 #ifndef CONFIG_SYS_MONITOR_LEN
 #define CONFIG_SYS_MONITOR_LEN (200 * 1024)
 #endif
@@ -75,23 +78,35 @@ void spl_parse_image_header(const struct image_header *header)
 {
        u32 header_size = sizeof(struct image_header);
 
-       if (__be32_to_cpu(header->ih_magic) == IH_MAGIC) {
-               spl_image.size = __be32_to_cpu(header->ih_size) + header_size;
-               spl_image.entry_point = __be32_to_cpu(header->ih_load);
-               /* Load including the header */
-               spl_image.load_addr = spl_image.entry_point - header_size;
-               spl_image.os = header->ih_os;
-               spl_image.name = (const char *)&header->ih_name;
+       if (image_get_magic(header) == IH_MAGIC) {
+               if (spl_image.flags & SPL_COPY_PAYLOAD_ONLY) {
+                       /*
+                        * On some system (e.g. powerpc), the load-address and
+                        * entry-point is located at address 0. We can't load
+                        * to 0-0x40. So skip header in this case.
+                        */
+                       spl_image.load_addr = image_get_load(header);
+                       spl_image.entry_point = image_get_ep(header);
+                       spl_image.size = image_get_data_size(header);
+               } else {
+                       spl_image.entry_point = image_get_load(header);
+                       /* Load including the header */
+                       spl_image.load_addr = spl_image.entry_point -
+                               header_size;
+                       spl_image.size = image_get_data_size(header) +
+                               header_size;
+               }
+               spl_image.os = image_get_os(header);
+               spl_image.name = image_get_name(header);
                debug("spl: payload image: %s load addr: 0x%x size: %d\n",
                        spl_image.name, spl_image.load_addr, spl_image.size);
        } else {
                /* Signature not found - assume u-boot.bin */
-               puts("mkimage signature not found, assuming u-boot.bin ..\n");
                debug("mkimage signature not found - ih_magic = %x\n",
                        header->ih_magic);
                /* Let's assume U-Boot will not be more than 200 KB */
                spl_image.size = CONFIG_SYS_MONITOR_LEN;
-               spl_image.entry_point = CONFIG_SYS_TEXT_BASE;
+               spl_image.entry_point = CONFIG_SYS_UBOOT_START;
                spl_image.load_addr = CONFIG_SYS_TEXT_BASE;
                spl_image.os = IH_OS_U_BOOT;
                spl_image.name = "U-Boot";
@@ -113,6 +128,23 @@ static void __noreturn jump_to_image_no_args(void)
        image_entry((u32 *)boot_params_ptr_addr);
 }
 
+#ifdef CONFIG_SPL_RAM_DEVICE
+static void spl_ram_load_image(void)
+{
+       const struct image_header *header;
+
+       /*
+        * Get the header.  It will point to an address defined by handoff
+        * which will tell where the image located inside the flash. For
+        * now, it will temporary fixed to address pointed by U-Boot.
+        */
+       header = (struct image_header *)
+               (CONFIG_SYS_TEXT_BASE - sizeof(struct image_header));
+
+       spl_parse_image_header(header);
+}
+#endif
+
 void board_init_r(gd_t *dummy1, ulong dummy2)
 {
        u32 boot_device;
@@ -130,6 +162,11 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
        boot_device = spl_boot_device();
        debug("boot device - %d\n", boot_device);
        switch (boot_device) {
+#ifdef CONFIG_SPL_RAM_DEVICE
+       case BOOT_DEVICE_RAM:
+               spl_ram_load_image();
+               break;
+#endif
 #ifdef CONFIG_SPL_MMC_SUPPORT
        case BOOT_DEVICE_MMC1:
        case BOOT_DEVICE_MMC2:
@@ -142,6 +179,11 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
                spl_nand_load_image();
                break;
 #endif
+#ifdef CONFIG_SPL_NOR_SUPPORT
+       case BOOT_DEVICE_NOR:
+               spl_nor_load_image();
+               break;
+#endif
 #ifdef CONFIG_SPL_YMODEM_SUPPORT
        case BOOT_DEVICE_UART:
                spl_ymodem_load_image();
@@ -149,32 +191,28 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 #endif
 #ifdef CONFIG_SPL_SPI_SUPPORT
        case BOOT_DEVICE_SPI:
-               spi_boot();
-       break;
+               spl_spi_load_image();
+               break;
 #endif
        default:
-               puts("SPL: Un-supported Boot Device\n");
-               debug("Found: %d\n", boot_device);
+               debug("SPL: Un-supported Boot Device\n");
                hang();
-               break;
        }
 
        switch (spl_image.os) {
        case IH_OS_U_BOOT:
                debug("Jumping to U-Boot\n");
-               jump_to_image_no_args();
                break;
 #ifdef CONFIG_SPL_OS_BOOT
        case IH_OS_LINUX:
                debug("Jumping to Linux\n");
                spl_board_prepare_for_linux();
                jump_to_image_linux((void *)CONFIG_SYS_SPL_ARGS_ADDR);
-               break;
 #endif
        default:
-               puts("Unsupported OS image.. Jumping nevertheless..\n");
-               jump_to_image_no_args();
+               debug("Unsupported OS image.. Jumping nevertheless..\n");
        }
+       jump_to_image_no_args();
 }
 
 /*