wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Sysgo Real-Time Solutions, GmbH <www.elinos.com> |
| 4 | * Marius Groeger <mgroeger@sysgo.de> |
| 5 | * |
| 6 | * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl) |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
wdenk | 232c150 | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
wdenk | 232c150 | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <command.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 26 | #include <image.h> |
Jean-Christophe PLAGNIOL-VILLARD | a31e091 | 2009-04-04 12:49:11 +0200 | [diff] [blame] | 27 | #include <u-boot/zlib.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 28 | #include <asm/byteorder.h> |
| 29 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 32 | #if defined (CONFIG_SETUP_MEMORY_TAGS) || \ |
| 33 | defined (CONFIG_CMDLINE_TAG) || \ |
| 34 | defined (CONFIG_INITRD_TAG) || \ |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 35 | defined (CONFIG_SERIAL_TAG) || \ |
Minkyu Kang | 47ea6ed | 2010-06-18 19:31:10 +0900 | [diff] [blame] | 36 | defined (CONFIG_REVISION_TAG) |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 37 | static void setup_start_tag (bd_t *bd); |
| 38 | |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 39 | # ifdef CONFIG_SETUP_MEMORY_TAGS |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 40 | static void setup_memory_tags (bd_t *bd); |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 41 | # endif |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 42 | static void setup_commandline_tag (bd_t *bd, char *commandline); |
| 43 | |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 44 | # ifdef CONFIG_INITRD_TAG |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 45 | static void setup_initrd_tag (bd_t *bd, ulong initrd_start, |
| 46 | ulong initrd_end); |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 47 | # endif |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 48 | static void setup_end_tag (bd_t *bd); |
| 49 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 50 | static struct tag *params; |
| 51 | #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */ |
| 52 | |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 53 | int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 54 | { |
Marian Balakowicz | d5934ad | 2008-02-04 08:28:09 +0100 | [diff] [blame] | 55 | bd_t *bd = gd->bd; |
| 56 | char *s; |
| 57 | int machid = bd->bi_arch_number; |
| 58 | void (*theKernel)(int zero, int arch, uint params); |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 59 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 60 | #ifdef CONFIG_CMDLINE_TAG |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 61 | char *commandline = getenv ("bootargs"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 62 | #endif |
| 63 | |
Ilko Iliev | 263b749 | 2008-11-09 15:53:14 +0100 | [diff] [blame] | 64 | if ((flag != 0) && (flag != BOOTM_STATE_OS_GO)) |
Kumar Gala | 49c3a86 | 2008-10-21 17:25:45 -0500 | [diff] [blame] | 65 | return 1; |
| 66 | |
Kumar Gala | c160a95 | 2008-08-15 08:24:36 -0500 | [diff] [blame] | 67 | theKernel = (void (*)(int, int, uint))images->ep; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 68 | |
Uwe Kleine-König | 3c234ef | 2008-01-30 09:08:49 +0100 | [diff] [blame] | 69 | s = getenv ("machid"); |
| 70 | if (s) { |
| 71 | machid = simple_strtoul (s, NULL, 16); |
| 72 | printf ("Using machid 0x%x from environment\n", machid); |
| 73 | } |
| 74 | |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 75 | show_boot_progress (15); |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 76 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 77 | debug ("## Transferring control to Linux (at address %08lx) ...\n", |
| 78 | (ulong) theKernel); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 79 | |
| 80 | #if defined (CONFIG_SETUP_MEMORY_TAGS) || \ |
| 81 | defined (CONFIG_CMDLINE_TAG) || \ |
| 82 | defined (CONFIG_INITRD_TAG) || \ |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 83 | defined (CONFIG_SERIAL_TAG) || \ |
Minkyu Kang | 47ea6ed | 2010-06-18 19:31:10 +0900 | [diff] [blame] | 84 | defined (CONFIG_REVISION_TAG) |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 85 | setup_start_tag (bd); |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 86 | #ifdef CONFIG_SERIAL_TAG |
| 87 | setup_serial_tag (¶ms); |
| 88 | #endif |
| 89 | #ifdef CONFIG_REVISION_TAG |
| 90 | setup_revision_tag (¶ms); |
| 91 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 92 | #ifdef CONFIG_SETUP_MEMORY_TAGS |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 93 | setup_memory_tags (bd); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 94 | #endif |
| 95 | #ifdef CONFIG_CMDLINE_TAG |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 96 | setup_commandline_tag (bd, commandline); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 97 | #endif |
| 98 | #ifdef CONFIG_INITRD_TAG |
Kumar Gala | c4f9419 | 2008-08-15 08:24:37 -0500 | [diff] [blame] | 99 | if (images->rd_start && images->rd_end) |
| 100 | setup_initrd_tag (bd, images->rd_start, images->rd_end); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 101 | #endif |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 102 | setup_end_tag (bd); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 103 | #endif |
| 104 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 105 | /* we assume that the kernel is in place */ |
| 106 | printf ("\nStarting kernel ...\n\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 107 | |
wdenk | 232c150 | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 108 | #ifdef CONFIG_USB_DEVICE |
| 109 | { |
| 110 | extern void udc_disconnect (void); |
| 111 | udc_disconnect (); |
| 112 | } |
| 113 | #endif |
| 114 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 115 | cleanup_before_linux (); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 116 | |
Uwe Kleine-König | 3c234ef | 2008-01-30 09:08:49 +0100 | [diff] [blame] | 117 | theKernel (0, machid, bd->bi_boot_params); |
Marian Balakowicz | cd7c596 | 2008-03-12 10:33:00 +0100 | [diff] [blame] | 118 | /* does not return */ |
Wolfgang Denk | 1055171 | 2008-09-08 23:26:22 +0200 | [diff] [blame] | 119 | |
Kumar Gala | 40d7e99 | 2008-08-15 08:24:45 -0500 | [diff] [blame] | 120 | return 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | |
| 124 | #if defined (CONFIG_SETUP_MEMORY_TAGS) || \ |
| 125 | defined (CONFIG_CMDLINE_TAG) || \ |
| 126 | defined (CONFIG_INITRD_TAG) || \ |
wdenk | b6e4c40 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 127 | defined (CONFIG_SERIAL_TAG) || \ |
Minkyu Kang | 47ea6ed | 2010-06-18 19:31:10 +0900 | [diff] [blame] | 128 | defined (CONFIG_REVISION_TAG) |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 129 | static void setup_start_tag (bd_t *bd) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 130 | { |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 131 | params = (struct tag *) bd->bi_boot_params; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 132 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 133 | params->hdr.tag = ATAG_CORE; |
| 134 | params->hdr.size = tag_size (tag_core); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 135 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 136 | params->u.core.flags = 0; |
| 137 | params->u.core.pagesize = 0; |
| 138 | params->u.core.rootdev = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 139 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 140 | params = tag_next (params); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 144 | #ifdef CONFIG_SETUP_MEMORY_TAGS |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 145 | static void setup_memory_tags (bd_t *bd) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 146 | { |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 147 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 148 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 149 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 150 | params->hdr.tag = ATAG_MEM; |
| 151 | params->hdr.size = tag_size (tag_mem32); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 152 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 153 | params->u.mem.start = bd->bi_dram[i].start; |
| 154 | params->u.mem.size = bd->bi_dram[i].size; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 155 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 156 | params = tag_next (params); |
| 157 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 158 | } |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 159 | #endif /* CONFIG_SETUP_MEMORY_TAGS */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 160 | |
| 161 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 162 | static void setup_commandline_tag (bd_t *bd, char *commandline) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 163 | { |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 164 | char *p; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 165 | |
wdenk | 109c0e3 | 2004-03-23 21:43:07 +0000 | [diff] [blame] | 166 | if (!commandline) |
| 167 | return; |
| 168 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 169 | /* eat leading white space */ |
| 170 | for (p = commandline; *p == ' '; p++); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 171 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 172 | /* skip non-existent command lines so the kernel will still |
| 173 | * use its default command line. |
| 174 | */ |
| 175 | if (*p == '\0') |
| 176 | return; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 177 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 178 | params->hdr.tag = ATAG_CMDLINE; |
| 179 | params->hdr.size = |
| 180 | (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 181 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 182 | strcpy (params->u.cmdline.cmdline, p); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 183 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 184 | params = tag_next (params); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 188 | #ifdef CONFIG_INITRD_TAG |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 189 | static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 190 | { |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 191 | /* an ATAG_INITRD node tells the kernel where the compressed |
| 192 | * ramdisk can be found. ATAG_RDIMG is a better name, actually. |
| 193 | */ |
wdenk | 498b8db | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 194 | params->hdr.tag = ATAG_INITRD2; |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 195 | params->hdr.size = tag_size (tag_initrd); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 196 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 197 | params->u.initrd.start = initrd_start; |
| 198 | params->u.initrd.size = initrd_end - initrd_start; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 199 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 200 | params = tag_next (params); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 201 | } |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 202 | #endif /* CONFIG_INITRD_TAG */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 203 | |
wdenk | 3a574cb | 2005-05-19 22:39:42 +0000 | [diff] [blame] | 204 | #ifdef CONFIG_SERIAL_TAG |
| 205 | void setup_serial_tag (struct tag **tmp) |
| 206 | { |
| 207 | struct tag *params = *tmp; |
| 208 | struct tag_serialnr serialnr; |
| 209 | void get_board_serial(struct tag_serialnr *serialnr); |
| 210 | |
| 211 | get_board_serial(&serialnr); |
| 212 | params->hdr.tag = ATAG_SERIAL; |
| 213 | params->hdr.size = tag_size (tag_serialnr); |
| 214 | params->u.serialnr.low = serialnr.low; |
| 215 | params->u.serialnr.high= serialnr.high; |
| 216 | params = tag_next (params); |
| 217 | *tmp = params; |
| 218 | } |
| 219 | #endif |
| 220 | |
wdenk | 289f932 | 2005-01-12 00:15:14 +0000 | [diff] [blame] | 221 | #ifdef CONFIG_REVISION_TAG |
| 222 | void setup_revision_tag(struct tag **in_params) |
| 223 | { |
| 224 | u32 rev = 0; |
wdenk | 289f932 | 2005-01-12 00:15:14 +0000 | [diff] [blame] | 225 | u32 get_board_rev(void); |
| 226 | |
| 227 | rev = get_board_rev(); |
wdenk | 289f932 | 2005-01-12 00:15:14 +0000 | [diff] [blame] | 228 | params->hdr.tag = ATAG_REVISION; |
| 229 | params->hdr.size = tag_size (tag_revision); |
| 230 | params->u.revision.rev = rev; |
| 231 | params = tag_next (params); |
| 232 | } |
| 233 | #endif /* CONFIG_REVISION_TAG */ |
| 234 | |
| 235 | |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 236 | static void setup_end_tag (bd_t *bd) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 237 | { |
wdenk | 5779d8d | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 238 | params->hdr.tag = ATAG_NONE; |
| 239 | params->hdr.size = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */ |