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 | 29e7f5a | 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 | 29e7f5a | 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> |
| 27 | #include <zlib.h> |
| 28 | #include <asm/byteorder.h> |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 29 | #ifdef CONFIG_HAS_DATAFLASH |
| 30 | #include <dataflash.h> |
| 31 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 32 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 35 | /*cmd_boot.c*/ |
| 36 | extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 37 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 38 | #if defined (CONFIG_SETUP_MEMORY_TAGS) || \ |
| 39 | defined (CONFIG_CMDLINE_TAG) || \ |
| 40 | defined (CONFIG_INITRD_TAG) || \ |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 41 | defined (CONFIG_SERIAL_TAG) || \ |
| 42 | defined (CONFIG_REVISION_TAG) || \ |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 43 | defined (CONFIG_VFD) || \ |
| 44 | defined (CONFIG_LCD) |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 45 | static void setup_start_tag (bd_t *bd); |
| 46 | |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 47 | # ifdef CONFIG_SETUP_MEMORY_TAGS |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 48 | static void setup_memory_tags (bd_t *bd); |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 49 | # endif |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 50 | static void setup_commandline_tag (bd_t *bd, char *commandline); |
| 51 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 52 | #if 0 |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 53 | static void setup_ramdisk_tag (bd_t *bd); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 54 | #endif |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 55 | # ifdef CONFIG_INITRD_TAG |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 56 | static void setup_initrd_tag (bd_t *bd, ulong initrd_start, |
| 57 | ulong initrd_end); |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 58 | # endif |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 59 | static void setup_end_tag (bd_t *bd); |
| 60 | |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 61 | # if defined (CONFIG_VFD) || defined (CONFIG_LCD) |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 62 | static void setup_videolfb_tag (gd_t *gd); |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 63 | # endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 64 | |
| 65 | |
| 66 | static struct tag *params; |
| 67 | #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */ |
| 68 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 69 | extern image_header_t header; /* from cmd_bootm.c */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 70 | |
| 71 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 72 | void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], |
| 73 | ulong addr, ulong *len_ptr, int verify) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 74 | { |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 75 | ulong len = 0, checksum; |
| 76 | ulong initrd_start, initrd_end; |
| 77 | ulong data; |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 78 | void (*theKernel)(int zero, int arch, uint params); |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 79 | image_header_t *hdr = &header; |
| 80 | bd_t *bd = gd->bd; |
Uwe Kleine-König | 533937d | 2008-01-30 09:08:49 +0100 | [diff] [blame] | 81 | int machid = bd->bi_arch_number; |
| 82 | char *s; |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 83 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 84 | #ifdef CONFIG_CMDLINE_TAG |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 85 | char *commandline = getenv ("bootargs"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 86 | #endif |
| 87 | |
wdenk | 4ea537d | 2003-12-07 18:32:37 +0000 | [diff] [blame] | 88 | theKernel = (void (*)(int, int, uint))ntohl(hdr->ih_ep); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 89 | |
Uwe Kleine-König | 533937d | 2008-01-30 09:08:49 +0100 | [diff] [blame] | 90 | s = getenv ("machid"); |
| 91 | if (s) { |
| 92 | machid = simple_strtoul (s, NULL, 16); |
| 93 | printf ("Using machid 0x%x from environment\n", machid); |
| 94 | } |
| 95 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 96 | /* |
| 97 | * Check if there is an initrd image |
| 98 | */ |
| 99 | if (argc >= 3) { |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 100 | show_boot_progress (9); |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 101 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 102 | addr = simple_strtoul (argv[2], NULL, 16); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 103 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 104 | printf ("## Loading Ramdisk Image at %08lx ...\n", addr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 105 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 106 | /* Copy header so we can blank CRC field for re-calculation */ |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 107 | #ifdef CONFIG_HAS_DATAFLASH |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 108 | if (addr_dataflash (addr)) { |
| 109 | read_dataflash (addr, sizeof (image_header_t), |
| 110 | (char *) &header); |
| 111 | } else |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 112 | #endif |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 113 | memcpy (&header, (char *) addr, |
| 114 | sizeof (image_header_t)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 115 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 116 | if (ntohl (hdr->ih_magic) != IH_MAGIC) { |
| 117 | printf ("Bad Magic Number\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 118 | show_boot_progress (-10); |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 119 | do_reset (cmdtp, flag, argc, argv); |
| 120 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 121 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 122 | data = (ulong) & header; |
| 123 | len = sizeof (image_header_t); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 124 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 125 | checksum = ntohl (hdr->ih_hcrc); |
| 126 | hdr->ih_hcrc = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 127 | |
Wolfgang Denk | 7fa6e90 | 2006-03-11 22:53:33 +0100 | [diff] [blame] | 128 | if (crc32 (0, (unsigned char *) data, len) != checksum) { |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 129 | printf ("Bad Header Checksum\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 130 | show_boot_progress (-11); |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 131 | do_reset (cmdtp, flag, argc, argv); |
| 132 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 133 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 134 | show_boot_progress (10); |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 135 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 136 | print_image_hdr (hdr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 137 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 138 | data = addr + sizeof (image_header_t); |
| 139 | len = ntohl (hdr->ih_size); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 140 | |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 141 | #ifdef CONFIG_HAS_DATAFLASH |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 142 | if (addr_dataflash (addr)) { |
| 143 | read_dataflash (data, len, (char *) CFG_LOAD_ADDR); |
| 144 | data = CFG_LOAD_ADDR; |
| 145 | } |
wdenk | 381669a | 2003-06-16 23:50:08 +0000 | [diff] [blame] | 146 | #endif |
| 147 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 148 | if (verify) { |
| 149 | ulong csum = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 150 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 151 | printf (" Verifying Checksum ... "); |
Wolfgang Denk | 7fa6e90 | 2006-03-11 22:53:33 +0100 | [diff] [blame] | 152 | csum = crc32 (0, (unsigned char *) data, len); |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 153 | if (csum != ntohl (hdr->ih_dcrc)) { |
| 154 | printf ("Bad Data CRC\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 155 | show_boot_progress (-12); |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 156 | do_reset (cmdtp, flag, argc, argv); |
| 157 | } |
| 158 | printf ("OK\n"); |
| 159 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 160 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 161 | show_boot_progress (11); |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 162 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 163 | if ((hdr->ih_os != IH_OS_LINUX) || |
| 164 | (hdr->ih_arch != IH_CPU_ARM) || |
| 165 | (hdr->ih_type != IH_TYPE_RAMDISK)) { |
| 166 | printf ("No Linux ARM Ramdisk Image\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 167 | show_boot_progress (-13); |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 168 | do_reset (cmdtp, flag, argc, argv); |
| 169 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 170 | |
Timo Tuunainen | 7174cc0 | 2008-02-01 10:09:03 +0000 | [diff] [blame] | 171 | #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || \ |
| 172 | defined(CONFIG_ARMADILLO) || defined(CONFIG_M501SK) |
wdenk | b98ac28 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 173 | /* |
| 174 | *we need to copy the ramdisk to SRAM to let Linux boot |
| 175 | */ |
| 176 | memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len); |
| 177 | data = ntohl(hdr->ih_load); |
wdenk | 82db02f | 2004-07-11 22:19:26 +0000 | [diff] [blame] | 178 | #endif /* CONFIG_B2 || CONFIG_EVB4510 */ |
wdenk | b98ac28 | 2004-02-24 00:16:43 +0000 | [diff] [blame] | 179 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 180 | /* |
| 181 | * Now check if we have a multifile image |
| 182 | */ |
| 183 | } else if ((hdr->ih_type == IH_TYPE_MULTI) && (len_ptr[1])) { |
| 184 | ulong tail = ntohl (len_ptr[0]) % 4; |
| 185 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 186 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 187 | show_boot_progress (13); |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 188 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 189 | /* skip kernel length and terminator */ |
| 190 | data = (ulong) (&len_ptr[2]); |
| 191 | /* skip any additional image length fields */ |
| 192 | for (i = 1; len_ptr[i]; ++i) |
| 193 | data += 4; |
| 194 | /* add kernel length, and align */ |
| 195 | data += ntohl (len_ptr[0]); |
| 196 | if (tail) { |
| 197 | data += 4 - tail; |
| 198 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 199 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 200 | len = ntohl (len_ptr[1]); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 201 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 202 | } else { |
| 203 | /* |
| 204 | * no initrd image |
| 205 | */ |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 206 | show_boot_progress (14); |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 207 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 208 | len = data = 0; |
| 209 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 210 | |
| 211 | #ifdef DEBUG |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 212 | if (!data) { |
| 213 | printf ("No initrd\n"); |
| 214 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 215 | #endif |
| 216 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 217 | if (data) { |
| 218 | initrd_start = data; |
| 219 | initrd_end = initrd_start + len; |
| 220 | } else { |
| 221 | initrd_start = 0; |
| 222 | initrd_end = 0; |
| 223 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 224 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 225 | show_boot_progress (15); |
wdenk | 384ae02 | 2002-11-05 00:17:55 +0000 | [diff] [blame] | 226 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 227 | debug ("## Transferring control to Linux (at address %08lx) ...\n", |
| 228 | (ulong) theKernel); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 229 | |
| 230 | #if defined (CONFIG_SETUP_MEMORY_TAGS) || \ |
| 231 | defined (CONFIG_CMDLINE_TAG) || \ |
| 232 | defined (CONFIG_INITRD_TAG) || \ |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 233 | defined (CONFIG_SERIAL_TAG) || \ |
| 234 | defined (CONFIG_REVISION_TAG) || \ |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 235 | defined (CONFIG_LCD) || \ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 236 | defined (CONFIG_VFD) |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 237 | setup_start_tag (bd); |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 238 | #ifdef CONFIG_SERIAL_TAG |
| 239 | setup_serial_tag (¶ms); |
| 240 | #endif |
| 241 | #ifdef CONFIG_REVISION_TAG |
| 242 | setup_revision_tag (¶ms); |
| 243 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 244 | #ifdef CONFIG_SETUP_MEMORY_TAGS |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 245 | setup_memory_tags (bd); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 246 | #endif |
| 247 | #ifdef CONFIG_CMDLINE_TAG |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 248 | setup_commandline_tag (bd, commandline); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 249 | #endif |
| 250 | #ifdef CONFIG_INITRD_TAG |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 251 | if (initrd_start && initrd_end) |
| 252 | setup_initrd_tag (bd, initrd_start, initrd_end); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 253 | #endif |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 254 | #if defined (CONFIG_VFD) || defined (CONFIG_LCD) |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 255 | setup_videolfb_tag ((gd_t *) gd); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 256 | #endif |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 257 | setup_end_tag (bd); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 258 | #endif |
| 259 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 260 | /* we assume that the kernel is in place */ |
| 261 | printf ("\nStarting kernel ...\n\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 262 | |
wdenk | 29e7f5a | 2004-03-12 00:14:09 +0000 | [diff] [blame] | 263 | #ifdef CONFIG_USB_DEVICE |
| 264 | { |
| 265 | extern void udc_disconnect (void); |
| 266 | udc_disconnect (); |
| 267 | } |
| 268 | #endif |
| 269 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 270 | cleanup_before_linux (); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 271 | |
Uwe Kleine-König | 533937d | 2008-01-30 09:08:49 +0100 | [diff] [blame] | 272 | theKernel (0, machid, bd->bi_boot_params); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | |
| 276 | #if defined (CONFIG_SETUP_MEMORY_TAGS) || \ |
| 277 | defined (CONFIG_CMDLINE_TAG) || \ |
| 278 | defined (CONFIG_INITRD_TAG) || \ |
wdenk | bc01dd5 | 2004-01-02 16:05:07 +0000 | [diff] [blame] | 279 | defined (CONFIG_SERIAL_TAG) || \ |
| 280 | defined (CONFIG_REVISION_TAG) || \ |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 281 | defined (CONFIG_LCD) || \ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 282 | defined (CONFIG_VFD) |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 283 | static void setup_start_tag (bd_t *bd) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 284 | { |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 285 | params = (struct tag *) bd->bi_boot_params; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 286 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 287 | params->hdr.tag = ATAG_CORE; |
| 288 | params->hdr.size = tag_size (tag_core); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 289 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 290 | params->u.core.flags = 0; |
| 291 | params->u.core.pagesize = 0; |
| 292 | params->u.core.rootdev = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 293 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 294 | params = tag_next (params); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 298 | #ifdef CONFIG_SETUP_MEMORY_TAGS |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 299 | static void setup_memory_tags (bd_t *bd) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 300 | { |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 301 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 302 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 303 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) { |
| 304 | params->hdr.tag = ATAG_MEM; |
| 305 | params->hdr.size = tag_size (tag_mem32); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 306 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 307 | params->u.mem.start = bd->bi_dram[i].start; |
| 308 | params->u.mem.size = bd->bi_dram[i].size; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 309 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 310 | params = tag_next (params); |
| 311 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 312 | } |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 313 | #endif /* CONFIG_SETUP_MEMORY_TAGS */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 314 | |
| 315 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 316 | static void setup_commandline_tag (bd_t *bd, char *commandline) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 317 | { |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 318 | char *p; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 319 | |
wdenk | f16b516 | 2004-03-23 21:43:07 +0000 | [diff] [blame] | 320 | if (!commandline) |
| 321 | return; |
| 322 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 323 | /* eat leading white space */ |
| 324 | for (p = commandline; *p == ' '; p++); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 325 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 326 | /* skip non-existent command lines so the kernel will still |
| 327 | * use its default command line. |
| 328 | */ |
| 329 | if (*p == '\0') |
| 330 | return; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 331 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 332 | params->hdr.tag = ATAG_CMDLINE; |
| 333 | params->hdr.size = |
| 334 | (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 335 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 336 | strcpy (params->u.cmdline.cmdline, p); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 337 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 338 | params = tag_next (params); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | |
wdenk | 699b13a | 2002-11-03 18:03:52 +0000 | [diff] [blame] | 342 | #ifdef CONFIG_INITRD_TAG |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 343 | 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] | 344 | { |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 345 | /* an ATAG_INITRD node tells the kernel where the compressed |
| 346 | * ramdisk can be found. ATAG_RDIMG is a better name, actually. |
| 347 | */ |
wdenk | 19c8fb7 | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 348 | params->hdr.tag = ATAG_INITRD2; |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 349 | params->hdr.size = tag_size (tag_initrd); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 350 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 351 | params->u.initrd.start = initrd_start; |
| 352 | params->u.initrd.size = initrd_end - initrd_start; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 353 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 354 | params = tag_next (params); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 355 | } |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 356 | #endif /* CONFIG_INITRD_TAG */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 357 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 358 | |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 359 | #if defined (CONFIG_VFD) || defined (CONFIG_LCD) |
| 360 | extern ulong calc_fbsize (void); |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 361 | static void setup_videolfb_tag (gd_t *gd) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 362 | { |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 363 | /* An ATAG_VIDEOLFB node tells the kernel where and how large |
| 364 | * the framebuffer for video was allocated (among other things). |
| 365 | * Note that a _physical_ address is passed ! |
| 366 | * |
| 367 | * We only use it to pass the address and size, the other entries |
| 368 | * in the tag_videolfb are not of interest. |
| 369 | */ |
| 370 | params->hdr.tag = ATAG_VIDEOLFB; |
| 371 | params->hdr.size = tag_size (tag_videolfb); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 372 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 373 | params->u.videolfb.lfb_base = (u32) gd->fb_base; |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 374 | /* Fb size is calculated according to parameters for our panel |
| 375 | */ |
| 376 | params->u.videolfb.lfb_size = calc_fbsize(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 377 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 378 | params = tag_next (params); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 379 | } |
wdenk | 9ca7bbc | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 380 | #endif /* CONFIG_VFD || CONFIG_LCD */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 381 | |
wdenk | a21ad7b | 2005-05-19 22:39:42 +0000 | [diff] [blame] | 382 | #ifdef CONFIG_SERIAL_TAG |
| 383 | void setup_serial_tag (struct tag **tmp) |
| 384 | { |
| 385 | struct tag *params = *tmp; |
| 386 | struct tag_serialnr serialnr; |
| 387 | void get_board_serial(struct tag_serialnr *serialnr); |
| 388 | |
| 389 | get_board_serial(&serialnr); |
| 390 | params->hdr.tag = ATAG_SERIAL; |
| 391 | params->hdr.size = tag_size (tag_serialnr); |
| 392 | params->u.serialnr.low = serialnr.low; |
| 393 | params->u.serialnr.high= serialnr.high; |
| 394 | params = tag_next (params); |
| 395 | *tmp = params; |
| 396 | } |
| 397 | #endif |
| 398 | |
wdenk | cb99da5 | 2005-01-12 00:15:14 +0000 | [diff] [blame] | 399 | #ifdef CONFIG_REVISION_TAG |
| 400 | void setup_revision_tag(struct tag **in_params) |
| 401 | { |
| 402 | u32 rev = 0; |
wdenk | cb99da5 | 2005-01-12 00:15:14 +0000 | [diff] [blame] | 403 | u32 get_board_rev(void); |
| 404 | |
| 405 | rev = get_board_rev(); |
wdenk | cb99da5 | 2005-01-12 00:15:14 +0000 | [diff] [blame] | 406 | params->hdr.tag = ATAG_REVISION; |
| 407 | params->hdr.size = tag_size (tag_revision); |
| 408 | params->u.revision.rev = rev; |
| 409 | params = tag_next (params); |
| 410 | } |
| 411 | #endif /* CONFIG_REVISION_TAG */ |
| 412 | |
| 413 | |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 414 | static void setup_end_tag (bd_t *bd) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 415 | { |
wdenk | 8676590 | 2003-12-06 23:55:10 +0000 | [diff] [blame] | 416 | params->hdr.tag = ATAG_NONE; |
| 417 | params->hdr.size = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */ |