wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 2 | * Copyright (c) 2011 The Chromium OS Authors. |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 3 | * (C) Copyright 2002 |
Albert ARIBAUD | fa82f87 | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 4 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 5 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 9 | /* |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 10 | * Linux x86 zImage and bzImage loading |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 11 | * |
| 12 | * based on the procdure described in |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 13 | * linux/Documentation/i386/boot.txt |
| 14 | */ |
| 15 | |
| 16 | #include <common.h> |
| 17 | #include <asm/io.h> |
| 18 | #include <asm/ptrace.h> |
| 19 | #include <asm/zimage.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 20 | #include <asm/byteorder.h> |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 21 | #include <asm/bootparam.h> |
Vadim Bendebury | 3cdc18a | 2012-10-23 18:04:34 +0000 | [diff] [blame] | 22 | #ifdef CONFIG_SYS_COREBOOT |
| 23 | #include <asm/arch/timestamp.h> |
| 24 | #endif |
Stefan Reinauer | 61e0ea9 | 2012-10-23 18:04:37 +0000 | [diff] [blame] | 25 | #include <linux/compiler.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * Memory lay-out: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 29 | * |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 30 | * relative to setup_base (which is 0x90000 currently) |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 31 | * |
| 32 | * 0x0000-0x7FFF Real mode kernel |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 33 | * 0x8000-0x8FFF Stack and heap |
| 34 | * 0x9000-0x90FF Kernel command line |
| 35 | */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 36 | #define DEFAULT_SETUP_BASE 0x90000 |
| 37 | #define COMMAND_LINE_OFFSET 0x9000 |
| 38 | #define HEAP_END_OFFSET 0x8e00 |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 39 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 40 | #define COMMAND_LINE_SIZE 2048 |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 41 | |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 42 | unsigned generic_install_e820_map(unsigned max_entries, |
| 43 | struct e820entry *entries) |
| 44 | { |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | unsigned install_e820_map(unsigned max_entries, |
| 49 | struct e820entry *entries) |
| 50 | __attribute__((weak, alias("generic_install_e820_map"))); |
| 51 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 52 | static void build_command_line(char *command_line, int auto_boot) |
| 53 | { |
| 54 | char *env_command_line; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 55 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 56 | command_line[0] = '\0'; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 57 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 58 | env_command_line = getenv("bootargs"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 59 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 60 | /* set console= argument if we use a serial console */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 61 | if (!strstr(env_command_line, "console=")) { |
| 62 | if (!strcmp(getenv("stdout"), "serial")) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 63 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 64 | /* We seem to use serial console */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 65 | sprintf(command_line, "console=ttyS0,%s ", |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 66 | getenv("baudrate")); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 67 | } |
| 68 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 69 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 70 | if (auto_boot) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 71 | strcat(command_line, "auto "); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 72 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 73 | if (env_command_line) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 74 | strcat(command_line, env_command_line); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 75 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 76 | printf("Kernel command line: \"%s\"\n", command_line); |
| 77 | } |
| 78 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 79 | static int kernel_magic_ok(struct setup_header *hdr) |
| 80 | { |
| 81 | if (KERNEL_MAGIC != hdr->boot_flag) { |
| 82 | printf("Error: Invalid Boot Flag " |
| 83 | "(found 0x%04x, expected 0x%04x)\n", |
| 84 | hdr->boot_flag, KERNEL_MAGIC); |
| 85 | return 0; |
| 86 | } else { |
| 87 | printf("Valid Boot Flag\n"); |
| 88 | return 1; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | static int get_boot_protocol(struct setup_header *hdr) |
| 93 | { |
| 94 | if (hdr->header == KERNEL_V2_MAGIC) { |
| 95 | printf("Magic signature found\n"); |
| 96 | return hdr->version; |
| 97 | } else { |
| 98 | /* Very old kernel */ |
| 99 | printf("Magic signature not found\n"); |
| 100 | return 0x0100; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | struct boot_params *load_zimage(char *image, unsigned long kernel_size, |
| 105 | void **load_address) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 106 | { |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 107 | struct boot_params *setup_base; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 108 | int setup_size; |
| 109 | int bootproto; |
| 110 | int big_image; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 111 | |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 112 | struct boot_params *params = (struct boot_params *)image; |
| 113 | struct setup_header *hdr = ¶ms->hdr; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 114 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 115 | /* base address for real-mode segment */ |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 116 | setup_base = (struct boot_params *)DEFAULT_SETUP_BASE; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 117 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 118 | if (!kernel_magic_ok(hdr)) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 119 | return 0; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 120 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 121 | /* determine size of setup */ |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 122 | if (0 == hdr->setup_sects) { |
| 123 | printf("Setup Sectors = 0 (defaulting to 4)\n"); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 124 | setup_size = 5 * 512; |
| 125 | } else { |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 126 | setup_size = (hdr->setup_sects + 1) * 512; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 127 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 128 | |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 129 | printf("Setup Size = 0x%8.8lx\n", (ulong)setup_size); |
| 130 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 131 | if (setup_size > SETUP_MAX_SIZE) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 132 | printf("Error: Setup is too large (%d bytes)\n", setup_size); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 133 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 134 | /* determine boot protocol version */ |
| 135 | bootproto = get_boot_protocol(hdr); |
| 136 | |
| 137 | printf("Using boot protocol version %x.%02x\n", |
| 138 | (bootproto & 0xff00) >> 8, bootproto & 0xff); |
| 139 | |
| 140 | if (bootproto >= 0x0200) { |
| 141 | if (hdr->setup_sects >= 15) { |
| 142 | printf("Linux kernel version %s\n", |
| 143 | (char *)params + |
| 144 | hdr->kernel_version + 0x200); |
| 145 | } else { |
| 146 | printf("Setup Sectors < 15 - " |
| 147 | "Cannot print kernel version.\n"); |
| 148 | } |
| 149 | } |
| 150 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 151 | /* Determine image type */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 152 | big_image = (bootproto >= 0x0200) && |
| 153 | (hdr->loadflags & BIG_KERNEL_FLAG); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 154 | |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 155 | /* Determine load address */ |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 156 | if (big_image) |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 157 | *load_address = (void *)BZIMAGE_LOAD_ADDR; |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 158 | else |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 159 | *load_address = (void *)ZIMAGE_LOAD_ADDR; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 160 | |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 161 | printf("Building boot_params at 0x%8.8lx\n", (ulong)setup_base); |
| 162 | memset(setup_base, 0, sizeof(*setup_base)); |
| 163 | setup_base->hdr = params->hdr; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 164 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 165 | if (bootproto >= 0x0204) |
| 166 | kernel_size = hdr->syssize * 16; |
| 167 | else |
| 168 | kernel_size -= setup_size; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 169 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 170 | if (bootproto == 0x0100) { |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 171 | /* |
| 172 | * A very old kernel MUST have its real-mode code |
| 173 | * loaded at 0x90000 |
| 174 | */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 175 | if ((u32)setup_base != 0x90000) { |
| 176 | /* Copy the real-mode kernel */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 177 | memmove((void *)0x90000, setup_base, setup_size); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 178 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 179 | /* Copy the command line */ |
| 180 | memmove((void *)0x99000, |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 181 | (u8 *)setup_base + COMMAND_LINE_OFFSET, |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 182 | COMMAND_LINE_SIZE); |
| 183 | |
| 184 | /* Relocated */ |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 185 | setup_base = (struct boot_params *)0x90000; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 186 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 187 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 188 | /* It is recommended to clear memory up to the 32K mark */ |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 189 | memset((u8 *)0x90000 + setup_size, 0, |
| 190 | SETUP_MAX_SIZE - setup_size); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 191 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 192 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 193 | if (big_image) { |
| 194 | if (kernel_size > BZIMAGE_MAX_SIZE) { |
| 195 | printf("Error: bzImage kernel too big! " |
| 196 | "(size: %ld, max: %d)\n", |
| 197 | kernel_size, BZIMAGE_MAX_SIZE); |
| 198 | return 0; |
| 199 | } |
| 200 | } else if ((kernel_size) > ZIMAGE_MAX_SIZE) { |
| 201 | printf("Error: zImage kernel too big! (size: %ld, max: %d)\n", |
| 202 | kernel_size, ZIMAGE_MAX_SIZE); |
| 203 | return 0; |
| 204 | } |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 205 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 206 | printf("Loading %s at address %p (%ld bytes)\n", |
| 207 | big_image ? "bzImage" : "zImage", *load_address, kernel_size); |
| 208 | |
| 209 | memmove(*load_address, image + setup_size, kernel_size); |
| 210 | |
| 211 | return setup_base; |
| 212 | } |
| 213 | |
| 214 | int setup_zimage(struct boot_params *setup_base, char *cmd_line, int auto_boot, |
| 215 | unsigned long initrd_addr, unsigned long initrd_size) |
| 216 | { |
| 217 | struct setup_header *hdr = &setup_base->hdr; |
| 218 | int bootproto = get_boot_protocol(hdr); |
| 219 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 220 | setup_base->e820_entries = install_e820_map( |
| 221 | ARRAY_SIZE(setup_base->e820_map), setup_base->e820_map); |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 222 | |
| 223 | if (bootproto == 0x0100) { |
| 224 | setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC; |
| 225 | setup_base->screen_info.cl_offset = COMMAND_LINE_OFFSET; |
| 226 | } |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 227 | if (bootproto >= 0x0200) { |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 228 | hdr->type_of_loader = 8; |
| 229 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 230 | if (initrd_addr) { |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 231 | printf("Initial RAM disk at linear address " |
| 232 | "0x%08lx, size %ld bytes\n", |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 233 | initrd_addr, initrd_size); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 234 | |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 235 | hdr->ramdisk_image = initrd_addr; |
| 236 | hdr->ramdisk_size = initrd_size; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 237 | } |
| 238 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 239 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 240 | if (bootproto >= 0x0201) { |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 241 | hdr->heap_end_ptr = HEAP_END_OFFSET; |
| 242 | hdr->loadflags |= HEAP_FLAG; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 243 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 244 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 245 | if (bootproto >= 0x0202) { |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 246 | hdr->cmd_line_ptr = (uintptr_t)cmd_line; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 247 | } else if (bootproto >= 0x0200) { |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 248 | setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC; |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 249 | setup_base->screen_info.cl_offset = |
| 250 | (uintptr_t)cmd_line - (uintptr_t)setup_base; |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 251 | |
| 252 | hdr->setup_move_size = 0x9100; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 253 | } |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 254 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 255 | /* build command line at COMMAND_LINE_OFFSET */ |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 256 | build_command_line(cmd_line, auto_boot); |
| 257 | return 0; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Stefan Reinauer | 61e0ea9 | 2012-10-23 18:04:37 +0000 | [diff] [blame] | 260 | /* |
| 261 | * Implement a weak default function for boards that optionally |
| 262 | * need to clean up the system before jumping to the kernel. |
| 263 | */ |
| 264 | __weak void board_final_cleanup(void) |
| 265 | { |
| 266 | } |
| 267 | |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 268 | void boot_zimage(void *setup_base, void *load_address) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 269 | { |
Simon Glass | 7949703 | 2013-04-17 16:13:35 +0000 | [diff] [blame] | 270 | debug("## Transferring control to Linux (at address %08x) ...\n", |
| 271 | (u32)setup_base); |
| 272 | |
| 273 | bootstage_mark_name(BOOTSTAGE_ID_BOOTM_HANDOFF, "start_kernel"); |
| 274 | #ifdef CONFIG_BOOTSTAGE_REPORT |
| 275 | bootstage_report(); |
| 276 | #endif |
Stefan Reinauer | 61e0ea9 | 2012-10-23 18:04:37 +0000 | [diff] [blame] | 277 | board_final_cleanup(); |
| 278 | |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 279 | printf("\nStarting kernel ...\n\n"); |
| 280 | |
Vadim Bendebury | 3cdc18a | 2012-10-23 18:04:34 +0000 | [diff] [blame] | 281 | #ifdef CONFIG_SYS_COREBOOT |
| 282 | timestamp_add_now(TS_U_BOOT_START_KERNEL); |
| 283 | #endif |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 284 | /* |
| 285 | * Set %ebx, %ebp, and %edi to 0, %esi to point to the boot_params |
| 286 | * structure, and then jump to the kernel. We assume that %cs is |
| 287 | * 0x10, 4GB flat, and read/execute, and the data segments are 0x18, |
| 288 | * 4GB flat, and read/write. U-boot is setting them up that way for |
| 289 | * itself in arch/i386/cpu/cpu.c. |
| 290 | */ |
| 291 | __asm__ __volatile__ ( |
Simon Glass | 1484311 | 2012-10-23 18:04:40 +0000 | [diff] [blame] | 292 | "movl $0, %%ebp\n" |
| 293 | "cli\n" |
| 294 | "jmp *%[kernel_entry]\n" |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 295 | :: [kernel_entry]"a"(load_address), |
| 296 | [boot_params] "S"(setup_base), |
| 297 | "b"(0), "D"(0) |
| 298 | : "%ebp" |
| 299 | ); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 300 | } |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 301 | |
Graeme Russ | 8e18e6e | 2011-12-23 10:20:55 +1100 | [diff] [blame] | 302 | void setup_pcat_compatibility(void) |
| 303 | __attribute__((weak, alias("__setup_pcat_compatibility"))); |
| 304 | |
| 305 | void __setup_pcat_compatibility(void) |
| 306 | { |
| 307 | } |
| 308 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 309 | int do_zboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 310 | { |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 311 | struct boot_params *base_ptr; |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 312 | void *bzImage_addr = NULL; |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 313 | void *load_address; |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 314 | char *s; |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 315 | ulong bzImage_size = 0; |
Gabe Black | 6f9d998 | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 316 | ulong initrd_addr = 0; |
| 317 | ulong initrd_size = 0; |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 318 | |
| 319 | disable_interrupts(); |
| 320 | |
| 321 | /* Setup board for maximum PC/AT Compatibility */ |
| 322 | setup_pcat_compatibility(); |
| 323 | |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 324 | if (argc >= 2) { |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 325 | /* argv[1] holds the address of the bzImage */ |
| 326 | s = argv[1]; |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 327 | } else { |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 328 | s = getenv("fileaddr"); |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 329 | } |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 330 | |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 331 | if (s) |
| 332 | bzImage_addr = (void *)simple_strtoul(s, NULL, 16); |
| 333 | |
Gabe Black | 6f9d998 | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 334 | if (argc >= 3) { |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 335 | /* argv[2] holds the size of the bzImage */ |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 336 | bzImage_size = simple_strtoul(argv[2], NULL, 16); |
Gabe Black | 6f9d998 | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | if (argc >= 4) |
| 340 | initrd_addr = simple_strtoul(argv[3], NULL, 16); |
| 341 | if (argc >= 5) |
| 342 | initrd_size = simple_strtoul(argv[4], NULL, 16); |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 343 | |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 344 | /* Lets look for */ |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 345 | base_ptr = load_zimage(bzImage_addr, bzImage_size, &load_address); |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 346 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 347 | if (!base_ptr) { |
| 348 | printf("## Kernel loading failed ...\n"); |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 349 | return -1; |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 350 | } |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 351 | if (setup_zimage(base_ptr, (char *)base_ptr + COMMAND_LINE_OFFSET, |
Gabe Black | 6f9d998 | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 352 | 0, initrd_addr, initrd_size)) { |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 353 | printf("Setting up boot parameters failed ...\n"); |
| 354 | return -1; |
| 355 | } |
| 356 | |
Gabe Black | 69370d1 | 2011-12-05 12:09:26 +0000 | [diff] [blame] | 357 | /* we assume that the kernel is in place */ |
| 358 | boot_zimage(base_ptr, load_address); |
| 359 | /* does not return */ |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 360 | |
| 361 | return -1; |
| 362 | } |
| 363 | |
| 364 | U_BOOT_CMD( |
Gabe Black | 6f9d998 | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 365 | zboot, 5, 0, do_zboot, |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 366 | "Boot bzImage", |
Gabe Black | 6f9d998 | 2011-12-05 12:09:27 +0000 | [diff] [blame] | 367 | "[addr] [size] [initrd addr] [initrd size]\n" |
| 368 | " addr - The optional starting address of the bzimage.\n" |
| 369 | " If not set it defaults to the environment\n" |
| 370 | " variable \"fileaddr\".\n" |
| 371 | " size - The optional size of the bzimage. Defaults to\n" |
| 372 | " zero.\n" |
| 373 | " initrd addr - The address of the initrd image to use, if any.\n" |
| 374 | " initrd size - The size of the initrd image to use, if any.\n" |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 375 | ); |