wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 1 | /* |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame^] | 2 | * (C) Copyright 2007 Michal Simek |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 3 | * (C) Copyright 2004 Atmark Techno, Inc. |
| 4 | * |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame^] | 5 | * Michal SIMEK <monstr@monstr.eu> |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 6 | * Yasushi SHOJI <yashi@atmark-techno.com> |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame^] | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
| 27 | #include <common.h> |
| 28 | #include <command.h> |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame^] | 29 | #include <image.h> |
| 30 | #include <zlib.h> |
| 31 | #include <asm/byteorder.h> |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 32 | |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame^] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
| 35 | #ifdef CONFIG_SHOW_BOOT_PROGRESS |
| 36 | # include <status_led.h> |
| 37 | # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg) |
| 38 | #else |
| 39 | # define SHOW_BOOT_PROGRESS(arg) |
| 40 | #endif |
| 41 | |
| 42 | extern image_header_t header; /* from cmd_bootm.c */ |
| 43 | /*cmd_boot.c*/ |
| 44 | extern int do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]); |
| 45 | |
| 46 | void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], |
| 47 | ulong addr, ulong * len_ptr, int verify) |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 48 | { |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame^] | 49 | ulong len = 0, checksum; |
| 50 | ulong initrd_start, initrd_end; |
| 51 | ulong data; |
| 52 | /* First parameter is mapped to $r5 for kernel boot args */ |
| 53 | void (*theKernel) (char *); |
| 54 | image_header_t *hdr = &header; |
| 55 | char *commandline = getenv ("bootargs"); |
| 56 | int i; |
| 57 | |
| 58 | theKernel = (void (*)(char *))ntohl (hdr->ih_ep); |
| 59 | |
| 60 | /* Check if there is an initrd image */ |
| 61 | if (argc >= 3) { |
| 62 | SHOW_BOOT_PROGRESS (9); |
| 63 | |
| 64 | addr = simple_strtoul (argv[2], NULL, 16); |
| 65 | |
| 66 | printf ("## Loading Ramdisk Image at %08lx ...\n", addr); |
| 67 | |
| 68 | /* Copy header so we can blank CRC field for re-calculation */ |
| 69 | memcpy (&header, (char *)addr, sizeof (image_header_t)); |
| 70 | |
| 71 | if (ntohl (hdr->ih_magic) != IH_MAGIC) { |
| 72 | printf ("Bad Magic Number\n"); |
| 73 | SHOW_BOOT_PROGRESS (-10); |
| 74 | do_reset (cmdtp, flag, argc, argv); |
| 75 | } |
| 76 | |
| 77 | data = (ulong) & header; |
| 78 | len = sizeof (image_header_t); |
| 79 | |
| 80 | checksum = ntohl (hdr->ih_hcrc); |
| 81 | hdr->ih_hcrc = 0; |
| 82 | |
| 83 | if (crc32 (0, (char *)data, len) != checksum) { |
| 84 | printf ("Bad Header Checksum\n"); |
| 85 | SHOW_BOOT_PROGRESS (-11); |
| 86 | do_reset (cmdtp, flag, argc, argv); |
| 87 | } |
| 88 | |
| 89 | SHOW_BOOT_PROGRESS (10); |
| 90 | |
| 91 | print_image_hdr (hdr); |
| 92 | |
| 93 | data = addr + sizeof (image_header_t); |
| 94 | len = ntohl (hdr->ih_size); |
| 95 | |
| 96 | if (verify) { |
| 97 | ulong csum = 0; |
| 98 | |
| 99 | printf (" Verifying Checksum ... "); |
| 100 | csum = crc32 (0, (char *)data, len); |
| 101 | if (csum != ntohl (hdr->ih_dcrc)) { |
| 102 | printf ("Bad Data CRC\n"); |
| 103 | SHOW_BOOT_PROGRESS (-12); |
| 104 | do_reset (cmdtp, flag, argc, argv); |
| 105 | } |
| 106 | printf ("OK\n"); |
| 107 | } |
| 108 | |
| 109 | SHOW_BOOT_PROGRESS (11); |
| 110 | |
| 111 | if ((hdr->ih_os != IH_OS_LINUX) || |
| 112 | (hdr->ih_arch != IH_CPU_MICROBLAZE) || |
| 113 | (hdr->ih_type != IH_TYPE_RAMDISK)) { |
| 114 | printf ("No Linux Microblaze Ramdisk Image\n"); |
| 115 | SHOW_BOOT_PROGRESS (-13); |
| 116 | do_reset (cmdtp, flag, argc, argv); |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * Now check if we have a multifile image |
| 121 | */ |
| 122 | } else if ((hdr->ih_type == IH_TYPE_MULTI) && (len_ptr[1])) { |
| 123 | ulong tail = ntohl (len_ptr[0]) % 4; |
| 124 | |
| 125 | SHOW_BOOT_PROGRESS (13); |
| 126 | |
| 127 | /* skip kernel length and terminator */ |
| 128 | data = (ulong) (&len_ptr[2]); |
| 129 | /* skip any additional image length fields */ |
| 130 | for (i = 1; len_ptr[i]; ++i) |
| 131 | data += 4; |
| 132 | /* add kernel length, and align */ |
| 133 | data += ntohl (len_ptr[0]); |
| 134 | if (tail) { |
| 135 | data += 4 - tail; |
| 136 | } |
| 137 | |
| 138 | len = ntohl (len_ptr[1]); |
| 139 | |
| 140 | } else { |
| 141 | /* |
| 142 | * no initrd image |
| 143 | */ |
| 144 | SHOW_BOOT_PROGRESS (14); |
| 145 | |
| 146 | data = 0; |
| 147 | } |
| 148 | |
| 149 | #ifdef DEBUG |
| 150 | if (!data) { |
| 151 | printf ("No initrd\n"); |
| 152 | } |
| 153 | #endif |
| 154 | |
| 155 | if (data) { |
| 156 | initrd_start = data; |
| 157 | initrd_end = initrd_start + len; |
| 158 | } else { |
| 159 | initrd_start = 0; |
| 160 | initrd_end = 0; |
| 161 | } |
| 162 | |
| 163 | SHOW_BOOT_PROGRESS (15); |
| 164 | |
| 165 | #ifdef DEBUG |
| 166 | printf ("## Transferring control to Linux (at address %08lx) ...\n", |
| 167 | (ulong) theKernel); |
| 168 | #endif |
| 169 | |
| 170 | theKernel (commandline); |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 171 | } |