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 | * |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 25 | /* |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 26 | * Linux x86 zImage and bzImage loading |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 27 | * |
| 28 | * based on the procdure described in |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 29 | * linux/Documentation/i386/boot.txt |
| 30 | */ |
| 31 | |
| 32 | #include <common.h> |
| 33 | #include <asm/io.h> |
| 34 | #include <asm/ptrace.h> |
| 35 | #include <asm/zimage.h> |
| 36 | #include <asm/realmode.h> |
| 37 | #include <asm/byteorder.h> |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 38 | #include <asm/bootparam.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | * Memory lay-out: |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 42 | * |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 43 | * relative to setup_base (which is 0x90000 currently) |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 44 | * |
| 45 | * 0x0000-0x7FFF Real mode kernel |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 46 | * 0x8000-0x8FFF Stack and heap |
| 47 | * 0x9000-0x90FF Kernel command line |
| 48 | */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 49 | #define DEFAULT_SETUP_BASE 0x90000 |
| 50 | #define COMMAND_LINE_OFFSET 0x9000 |
| 51 | #define HEAP_END_OFFSET 0x8e00 |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 52 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 53 | #define COMMAND_LINE_SIZE 2048 |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 54 | |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 55 | unsigned generic_install_e820_map(unsigned max_entries, |
| 56 | struct e820entry *entries) |
| 57 | { |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | unsigned install_e820_map(unsigned max_entries, |
| 62 | struct e820entry *entries) |
| 63 | __attribute__((weak, alias("generic_install_e820_map"))); |
| 64 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 65 | static void build_command_line(char *command_line, int auto_boot) |
| 66 | { |
| 67 | char *env_command_line; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 68 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 69 | command_line[0] = '\0'; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 70 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 71 | env_command_line = getenv("bootargs"); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 72 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 73 | /* set console= argument if we use a serial console */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 74 | if (!strstr(env_command_line, "console=")) { |
| 75 | if (!strcmp(getenv("stdout"), "serial")) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 76 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 77 | /* We seem to use serial console */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 78 | sprintf(command_line, "console=ttyS0,%s ", |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 79 | getenv("baudrate")); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 80 | } |
| 81 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 82 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 83 | if (auto_boot) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 84 | strcat(command_line, "auto "); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 85 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 86 | if (env_command_line) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 87 | strcat(command_line, env_command_line); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 88 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 89 | printf("Kernel command line: \"%s\"\n", command_line); |
| 90 | } |
| 91 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 92 | void *load_zimage(char *image, unsigned long kernel_size, |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 93 | unsigned long initrd_addr, unsigned long initrd_size, |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 94 | int auto_boot, void **load_address) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 95 | { |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 96 | struct boot_params *setup_base; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 97 | int setup_size; |
| 98 | int bootproto; |
| 99 | int big_image; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 100 | |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 101 | struct boot_params *params = (struct boot_params *)image; |
| 102 | struct setup_header *hdr = ¶ms->hdr; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 103 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 104 | /* base address for real-mode segment */ |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 105 | setup_base = (struct boot_params *)DEFAULT_SETUP_BASE; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 106 | |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 107 | if (KERNEL_MAGIC != hdr->boot_flag) { |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 108 | printf("Error: Invalid Boot Flag " |
| 109 | "(found 0x%04x, expected 0x%04x)\n", |
| 110 | hdr->boot_flag, KERNEL_MAGIC); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 111 | return 0; |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 112 | } else { |
| 113 | printf("Valid Boot Flag\n"); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 114 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 115 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 116 | /* determine boot protocol version */ |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 117 | if (KERNEL_V2_MAGIC == hdr->header) { |
| 118 | printf("Magic signature found\n"); |
| 119 | |
| 120 | bootproto = hdr->version; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 121 | } else { |
| 122 | /* Very old kernel */ |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 123 | printf("Magic signature not found\n"); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 124 | bootproto = 0x0100; |
| 125 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 126 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 127 | /* determine size of setup */ |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 128 | if (0 == hdr->setup_sects) { |
| 129 | printf("Setup Sectors = 0 (defaulting to 4)\n"); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 130 | setup_size = 5 * 512; |
| 131 | } else { |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 132 | setup_size = (hdr->setup_sects + 1) * 512; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 133 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 134 | |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 135 | printf("Setup Size = 0x%8.8lx\n", (ulong)setup_size); |
| 136 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 137 | if (setup_size > SETUP_MAX_SIZE) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 138 | printf("Error: Setup is too large (%d bytes)\n", setup_size); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 139 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 140 | /* Determine image type */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 141 | big_image = (bootproto >= 0x0200) && |
| 142 | (hdr->loadflags & BIG_KERNEL_FLAG); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 143 | |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 144 | /* Determine load address */ |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 145 | if (big_image) |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 146 | *load_address = (void *)BZIMAGE_LOAD_ADDR; |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 147 | else |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 148 | *load_address = (void *)ZIMAGE_LOAD_ADDR; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 149 | |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 150 | #if defined CONFIG_ZBOOT_32 |
| 151 | printf("Building boot_params at 0x%8.8lx\n", (ulong)setup_base); |
| 152 | memset(setup_base, 0, sizeof(*setup_base)); |
| 153 | setup_base->hdr = params->hdr; |
| 154 | |
| 155 | setup_base->e820_entries = install_e820_map( |
| 156 | ARRAY_SIZE(setup_base->e820_map), setup_base->e820_map); |
| 157 | #else |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 158 | /* load setup */ |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 159 | printf("Moving Real-Mode Code to 0x%8.8lx (%d bytes)\n", |
| 160 | (ulong)setup_base, setup_size); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 161 | memmove(setup_base, image, setup_size); |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 162 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 163 | |
| 164 | printf("Using boot protocol version %x.%02x\n", |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 165 | (bootproto & 0xff00) >> 8, bootproto & 0xff); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 166 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 167 | if (bootproto == 0x0100) { |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 168 | setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC; |
| 169 | setup_base->screen_info.cl_offset = COMMAND_LINE_OFFSET; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 170 | |
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 | |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 193 | /* We are now setting up the real-mode version of the header */ |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 194 | hdr = &setup_base->hdr; |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 195 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 196 | if (bootproto >= 0x0200) { |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 197 | hdr->type_of_loader = 8; |
| 198 | |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 199 | if (hdr->setup_sects >= 15) { |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 200 | printf("Linux kernel version %s\n", |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 201 | (char *)params + |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 202 | hdr->kernel_version + 0x200); |
| 203 | } else { |
| 204 | printf("Setup Sectors < 15 - " |
| 205 | "Cannot print kernel version.\n"); |
| 206 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 207 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 208 | if (initrd_addr) { |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 209 | printf("Initial RAM disk at linear address " |
| 210 | "0x%08lx, size %ld bytes\n", |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 211 | initrd_addr, initrd_size); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 212 | |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 213 | hdr->ramdisk_image = initrd_addr; |
| 214 | hdr->ramdisk_size = initrd_size; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 217 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 218 | if (bootproto >= 0x0201) { |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 219 | hdr->heap_end_ptr = HEAP_END_OFFSET; |
| 220 | hdr->loadflags |= HEAP_FLAG; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 221 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 222 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 223 | if (bootproto >= 0x0202) { |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 224 | hdr->cmd_line_ptr = |
| 225 | (uintptr_t)setup_base + COMMAND_LINE_OFFSET; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 226 | } else if (bootproto >= 0x0200) { |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 227 | setup_base->screen_info.cl_magic = COMMAND_LINE_MAGIC; |
| 228 | setup_base->screen_info.cl_offset = COMMAND_LINE_OFFSET; |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 229 | |
| 230 | hdr->setup_move_size = 0x9100; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 231 | } |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 232 | |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 233 | if (bootproto >= 0x0204) |
| 234 | kernel_size = hdr->syssize * 16; |
| 235 | else |
| 236 | kernel_size -= setup_size; |
| 237 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 238 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 239 | if (big_image) { |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 240 | if ((kernel_size) > BZIMAGE_MAX_SIZE) { |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 241 | printf("Error: bzImage kernel too big! " |
| 242 | "(size: %ld, max: %d)\n", |
| 243 | kernel_size, BZIMAGE_MAX_SIZE); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 244 | return 0; |
| 245 | } |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 246 | } else if ((kernel_size) > ZIMAGE_MAX_SIZE) { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 247 | printf("Error: zImage kernel too big! (size: %ld, max: %d)\n", |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 248 | kernel_size, ZIMAGE_MAX_SIZE); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 249 | return 0; |
| 250 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 251 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 252 | /* build command line at COMMAND_LINE_OFFSET */ |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 253 | build_command_line((char *)setup_base + COMMAND_LINE_OFFSET, auto_boot); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 254 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 255 | printf("Loading %czImage at address 0x%08x (%ld bytes)\n", |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 256 | big_image ? 'b' : ' ', (u32)*load_address, kernel_size); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 257 | |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 258 | memmove(*load_address, image + setup_size, kernel_size); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 259 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 260 | /* ready for booting */ |
| 261 | return setup_base; |
| 262 | } |
| 263 | |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 264 | void boot_zimage(void *setup_base, void *load_address) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 265 | { |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 266 | printf("\nStarting kernel ...\n\n"); |
| 267 | |
| 268 | #if defined CONFIG_ZBOOT_32 |
| 269 | /* |
| 270 | * Set %ebx, %ebp, and %edi to 0, %esi to point to the boot_params |
| 271 | * structure, and then jump to the kernel. We assume that %cs is |
| 272 | * 0x10, 4GB flat, and read/execute, and the data segments are 0x18, |
| 273 | * 4GB flat, and read/write. U-boot is setting them up that way for |
| 274 | * itself in arch/i386/cpu/cpu.c. |
| 275 | */ |
| 276 | __asm__ __volatile__ ( |
| 277 | "movl $0, %%ebp \n" |
| 278 | "cli \n" |
| 279 | "jmp %[kernel_entry] \n" |
| 280 | :: [kernel_entry]"a"(load_address), |
| 281 | [boot_params] "S"(setup_base), |
| 282 | "b"(0), "D"(0) |
| 283 | : "%ebp" |
| 284 | ); |
| 285 | #else |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 286 | struct pt_regs regs; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 287 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 288 | memset(®s, 0, sizeof(struct pt_regs)); |
| 289 | regs.xds = (u32)setup_base >> 4; |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 290 | regs.xes = regs.xds; |
| 291 | regs.xss = regs.xds; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 292 | regs.esp = 0x9000; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 293 | regs.eflags = 0; |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 294 | enter_realmode(((u32)setup_base + SETUP_START_OFFSET) >> 4, 0, |
| 295 | ®s, ®s); |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 296 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 297 | } |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 298 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 299 | 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] | 300 | { |
| 301 | void *base_ptr; |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 302 | void *bzImage_addr = NULL; |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 303 | void *load_address; |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 304 | char *s; |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 305 | ulong bzImage_size = 0; |
| 306 | |
| 307 | disable_interrupts(); |
| 308 | |
| 309 | /* Setup board for maximum PC/AT Compatibility */ |
| 310 | setup_pcat_compatibility(); |
| 311 | |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 312 | if (argc >= 2) { |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 313 | /* argv[1] holds the address of the bzImage */ |
| 314 | s = argv[1]; |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 315 | } else { |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 316 | s = getenv("fileaddr"); |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 317 | } |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 318 | |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 319 | if (s) |
| 320 | bzImage_addr = (void *)simple_strtoul(s, NULL, 16); |
| 321 | |
| 322 | if (argc >= 3) |
| 323 | /* argv[2] holds the size of the bzImage */ |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 324 | bzImage_size = simple_strtoul(argv[2], NULL, 16); |
| 325 | |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 326 | /* Lets look for */ |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 327 | base_ptr = load_zimage(bzImage_addr, bzImage_size, 0, 0, 0, |
| 328 | &load_address); |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 329 | |
Graeme Russ | 83088af | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 330 | if (!base_ptr) { |
| 331 | printf("## Kernel loading failed ...\n"); |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 332 | } else { |
Gabe Black | d3a2bc3 | 2011-12-05 12:09:23 +0000 | [diff] [blame] | 333 | printf("## Transferring control to Linux " |
| 334 | "(at address %08x) ...\n", |
| 335 | (u32)base_ptr); |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 336 | |
| 337 | /* we assume that the kernel is in place */ |
Gabe Black | 233dbc1 | 2011-12-05 12:09:24 +0000 | [diff] [blame] | 338 | boot_zimage(base_ptr, load_address); |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 339 | /* does not return */ |
| 340 | } |
| 341 | |
| 342 | return -1; |
| 343 | } |
| 344 | |
| 345 | U_BOOT_CMD( |
Graeme Russ | abe98f4 | 2010-10-07 20:03:19 +1100 | [diff] [blame] | 346 | zboot, 2, 0, do_zboot, |
Graeme Russ | 95ffaba | 2010-04-24 00:05:49 +1000 | [diff] [blame] | 347 | "Boot bzImage", |
| 348 | "" |
| 349 | ); |