]> git.sur5r.net Git - u-boot/blobdiff - arch/x86/lib/zimage.c
Remove unnecessary instances of DECLARE_GLOBAL_DATA_PTR
[u-boot] / arch / x86 / lib / zimage.c
index 1dab3cc78878dcea322d1685f0df0ed388f7a70c..9932ee69a0c42a1672acb8ce955bc5543428ba10 100644 (file)
  */
 
 #include <common.h>
+#include <malloc.h>
+#include <asm/acpi_table.h>
 #include <asm/io.h>
 #include <asm/ptrace.h>
 #include <asm/zimage.h>
 #include <asm/byteorder.h>
+#include <asm/bootm.h>
 #include <asm/bootparam.h>
 #ifdef CONFIG_SYS_COREBOOT
 #include <asm/arch/timestamp.h>
 #endif
 #include <linux/compiler.h>
+#include <linux/libfdt.h>
 
 /*
  * Memory lay-out:
 
 #define COMMAND_LINE_SIZE      2048
 
-unsigned generic_install_e820_map(unsigned max_entries,
-                                 struct e820entry *entries)
-{
-       return 0;
-}
-
-unsigned install_e820_map(unsigned max_entries,
-                         struct e820entry *entries)
-       __attribute__((weak, alias("generic_install_e820_map")));
-
 static void build_command_line(char *command_line, int auto_boot)
 {
        char *env_command_line;
 
        command_line[0] = '\0';
 
-       env_command_line =  getenv("bootargs");
+       env_command_line =  env_get("bootargs");
 
        /* set console= argument if we use a serial console */
        if (!strstr(env_command_line, "console=")) {
-               if (!strcmp(getenv("stdout"), "serial")) {
+               if (!strcmp(env_get("stdout"), "serial")) {
 
                        /* We seem to use serial console */
                        sprintf(command_line, "console=ttyS0,%s ",
-                               getenv("baudrate"));
+                               env_get("baudrate"));
                }
        }
 
@@ -101,8 +95,40 @@ static int get_boot_protocol(struct setup_header *hdr)
        }
 }
 
+static int setup_device_tree(struct setup_header *hdr, const void *fdt_blob)
+{
+       int bootproto = get_boot_protocol(hdr);
+       struct setup_data *sd;
+       int size;
+
+       if (bootproto < 0x0209)
+               return -ENOTSUPP;
+
+       if (!fdt_blob)
+               return 0;
+
+       size = fdt_totalsize(fdt_blob);
+       if (size < 0)
+               return -EINVAL;
+
+       size += sizeof(struct setup_data);
+       sd = (struct setup_data *)malloc(size);
+       if (!sd) {
+               printf("Not enough memory for DTB setup data\n");
+               return -ENOMEM;
+       }
+
+       sd->next = hdr->setup_data;
+       sd->type = SETUP_DTB;
+       sd->len = fdt_totalsize(fdt_blob);
+       memcpy(sd->data, fdt_blob, sd->len);
+       hdr->setup_data = (unsigned long)sd;
+
+       return 0;
+}
+
 struct boot_params *load_zimage(char *image, unsigned long kernel_size,
-                               void **load_address)
+                               ulong *load_addressp)
 {
        struct boot_params *setup_base;
        int setup_size;
@@ -154,9 +180,9 @@ struct boot_params *load_zimage(char *image, unsigned long kernel_size,
 
        /* Determine load address */
        if (big_image)
-               *load_address = (void *)BZIMAGE_LOAD_ADDR;
+               *load_addressp = BZIMAGE_LOAD_ADDR;
        else
-               *load_address = (void *)ZIMAGE_LOAD_ADDR;
+               *load_addressp = ZIMAGE_LOAD_ADDR;
 
        printf("Building boot_params at 0x%8.8lx\n", (ulong)setup_base);
        memset(setup_base, 0, sizeof(*setup_base));
@@ -172,7 +198,7 @@ struct boot_params *load_zimage(char *image, unsigned long kernel_size,
                 * A very old kernel MUST have its real-mode code
                 * loaded at 0x90000
                 */
-               if ((u32)setup_base != 0x90000) {
+               if ((ulong)setup_base != 0x90000) {
                        /* Copy the real-mode kernel */
                        memmove((void *)0x90000, setup_base, setup_size);
 
@@ -203,10 +229,10 @@ struct boot_params *load_zimage(char *image, unsigned long kernel_size,
                return 0;
        }
 
-       printf("Loading %s at address %p (%ld bytes)\n",
-               big_image ? "bzImage" : "zImage", *load_address, kernel_size);
+       printf("Loading %s at address %lx (%ld bytes)\n",
+              big_image ? "bzImage" : "zImage", *load_addressp, kernel_size);
 
-       memmove(*load_address, image + setup_size, kernel_size);
+       memmove((void *)*load_addressp, image + setup_size, kernel_size);
 
        return setup_base;
 }
@@ -242,61 +268,35 @@ int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot,
                hdr->loadflags |= HEAP_FLAG;
        }
 
-       if (bootproto >= 0x0202) {
-               hdr->cmd_line_ptr = (uintptr_t)cmd_line;
-       } else if (bootproto >= 0x0200) {
-               setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC;
-               setup_base->screen_info.cl_offset =
-                       (uintptr_t)cmd_line - (uintptr_t)setup_base;
-
-               hdr->setup_move_size = 0x9100;
-       }
+       if (cmd_line) {
+               if (bootproto >= 0x0202) {
+                       hdr->cmd_line_ptr = (uintptr_t)cmd_line;
+               } else if (bootproto >= 0x0200) {
+                       setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC;
+                       setup_base->screen_info.cl_offset =
+                               (uintptr_t)cmd_line - (uintptr_t)setup_base;
 
-       /* build command line at COMMAND_LINE_OFFSET */
-       build_command_line(cmd_line, auto_boot);
-       return 0;
-}
+                       hdr->setup_move_size = 0x9100;
+               }
 
-/*
- * Implement a weak default function for boards that optionally
- * need to clean up the system before jumping to the kernel.
- */
-__weak void board_final_cleanup(void)
-{
-}
+               /* build command line at COMMAND_LINE_OFFSET */
+               build_command_line(cmd_line, auto_boot);
+       }
 
-void boot_zimage(void *setup_base, void *load_address)
-{
-       debug("## Transferring control to Linux (at address %08x) ...\n",
-             (u32)setup_base);
+#ifdef CONFIG_INTEL_MID
+       if (bootproto >= 0x0207)
+               hdr->hardware_subarch = X86_SUBARCH_INTEL_MID;
+#endif
 
-       bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel");
-#ifdef CONFIG_BOOTSTAGE_REPORT
-       bootstage_report();
+#ifdef CONFIG_GENERATE_ACPI_TABLE
+       if (bootproto >= 0x020e)
+               hdr->acpi_rsdp_addr = acpi_get_rsdp_addr();
 #endif
-       board_final_cleanup();
 
-       printf("\nStarting kernel ...\n\n");
+       setup_device_tree(hdr, (const void *)env_get_hex("fdtaddr", 0));
+       setup_video(&setup_base->screen_info);
 
-#ifdef CONFIG_SYS_COREBOOT
-       timestamp_add_now(TS_U_BOOT_START_KERNEL);
-#endif
-       /*
-        * Set %ebx, %ebp, and %edi to 0, %esi to point to the boot_params
-        * structure, and then jump to the kernel. We assume that %cs is
-        * 0x10, 4GB flat, and read/execute, and the data segments are 0x18,
-        * 4GB flat, and read/write. U-boot is setting them up that way for
-        * itself in arch/i386/cpu/cpu.c.
-        */
-       __asm__ __volatile__ (
-       "movl $0, %%ebp\n"
-       "cli\n"
-       "jmp *%[kernel_entry]\n"
-       :: [kernel_entry]"a"(load_address),
-          [boot_params] "S"(setup_base),
-          "b"(0), "D"(0)
-       :  "%ebp"
-       );
+       return 0;
 }
 
 void setup_pcat_compatibility(void)
@@ -310,7 +310,7 @@ int do_zboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 {
        struct boot_params *base_ptr;
        void *bzImage_addr = NULL;
-       void *load_address;
+       ulong load_address;
        char *s;
        ulong bzImage_size = 0;
        ulong initrd_addr = 0;
@@ -325,7 +325,7 @@ int do_zboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                /* argv[1] holds the address of the bzImage */
                s = argv[1];
        } else {
-               s = getenv("fileaddr");
+               s = env_get("fileaddr");
        }
 
        if (s)
@@ -345,20 +345,17 @@ int do_zboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
        base_ptr = load_zimage(bzImage_addr, bzImage_size, &load_address);
 
        if (!base_ptr) {
-               printf("## Kernel loading failed ...\n");
+               puts("## Kernel loading failed ...\n");
                return -1;
        }
        if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET,
                        0, initrd_addr, initrd_size)) {
-               printf("Setting up boot parameters failed ...\n");
+               puts("Setting up boot parameters failed ...\n");
                return -1;
        }
 
        /* we assume that the kernel is in place */
-       boot_zimage(base_ptr, load_address);
-       /* does not return */
-
-       return -1;
+       return boot_linux_kernel((ulong)base_ptr, load_address, false);
 }
 
 U_BOOT_CMD(