wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 1 | /* |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 2 | * (C) Copyright 2007 Michal Simek |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 3 | * (C) Copyright 2004 Atmark Techno, Inc. |
| 4 | * |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 5 | * Michal SIMEK <monstr@monstr.eu> |
wdenk | 1249065 | 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 | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | 1249065 | 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 | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 29 | #include <image.h> |
| 30 | #include <zlib.h> |
| 31 | #include <asm/byteorder.h> |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 32 | |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 35 | extern image_header_t header; /* from cmd_bootm.c */ |
| 36 | /*cmd_boot.c*/ |
| 37 | extern int do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]); |
| 38 | |
| 39 | void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], |
| 40 | ulong addr, ulong * len_ptr, int verify) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 41 | { |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 42 | ulong len = 0, checksum; |
| 43 | ulong initrd_start, initrd_end; |
| 44 | ulong data; |
| 45 | /* First parameter is mapped to $r5 for kernel boot args */ |
| 46 | void (*theKernel) (char *); |
| 47 | image_header_t *hdr = &header; |
| 48 | char *commandline = getenv ("bootargs"); |
| 49 | int i; |
| 50 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 51 | theKernel = (void (*)(char *))image_get_ep (hdr); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 52 | |
| 53 | /* Check if there is an initrd image */ |
| 54 | if (argc >= 3) { |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 55 | show_boot_progress (9); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 56 | |
| 57 | addr = simple_strtoul (argv[2], NULL, 16); |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 58 | hdr = (image_header_t *)addr; |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 59 | |
| 60 | printf ("## Loading Ramdisk Image at %08lx ...\n", addr); |
| 61 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 62 | if (!image_check_magic (hdr)) { |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 63 | printf ("Bad Magic Number\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 64 | show_boot_progress (-10); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 65 | do_reset (cmdtp, flag, argc, argv); |
| 66 | } |
| 67 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 68 | if (!image_check_magic (hdr)) { |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 69 | printf ("Bad Header Checksum\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 70 | show_boot_progress (-11); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 71 | do_reset (cmdtp, flag, argc, argv); |
| 72 | } |
| 73 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 74 | show_boot_progress (10); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 75 | |
| 76 | print_image_hdr (hdr); |
| 77 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 78 | data = image_get_data (hdr); |
| 79 | len = image_get_data_size (hdr); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 80 | |
| 81 | if (verify) { |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 82 | printf (" Verifying Checksum ... "); |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 83 | if (!image_check_dcrc (hdr)) { |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 84 | printf ("Bad Data CRC\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 85 | show_boot_progress (-12); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 86 | do_reset (cmdtp, flag, argc, argv); |
| 87 | } |
| 88 | printf ("OK\n"); |
| 89 | } |
| 90 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 91 | show_boot_progress (11); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 92 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 93 | if (!image_check_os (hdr, IH_OS_LINUX) || |
| 94 | !image_check_arch (hdr, IH_ARCH_MICROBLAZE) || |
| 95 | !image_check_type (hdr, IH_TYPE_RAMDISK)) { |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 96 | printf ("No Linux Microblaze Ramdisk Image\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 97 | show_boot_progress (-13); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 98 | do_reset (cmdtp, flag, argc, argv); |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * Now check if we have a multifile image |
| 103 | */ |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 104 | } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) { |
| 105 | ulong tail = image_to_cpu (len_ptr[0]) % 4; |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 106 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 107 | show_boot_progress (13); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 108 | |
| 109 | /* skip kernel length and terminator */ |
| 110 | data = (ulong) (&len_ptr[2]); |
| 111 | /* skip any additional image length fields */ |
| 112 | for (i = 1; len_ptr[i]; ++i) |
| 113 | data += 4; |
| 114 | /* add kernel length, and align */ |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 115 | data += image_to_cpu (len_ptr[0]); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 116 | if (tail) { |
| 117 | data += 4 - tail; |
| 118 | } |
| 119 | |
Marian Balakowicz | 41d71ed | 2008-01-08 18:14:09 +0100 | [diff] [blame] | 120 | len = image_to_cpu (len_ptr[1]); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 121 | |
| 122 | } else { |
| 123 | /* |
| 124 | * no initrd image |
| 125 | */ |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 126 | show_boot_progress (14); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 127 | |
| 128 | data = 0; |
| 129 | } |
| 130 | |
| 131 | #ifdef DEBUG |
| 132 | if (!data) { |
| 133 | printf ("No initrd\n"); |
| 134 | } |
| 135 | #endif |
| 136 | |
| 137 | if (data) { |
| 138 | initrd_start = data; |
| 139 | initrd_end = initrd_start + len; |
| 140 | } else { |
| 141 | initrd_start = 0; |
| 142 | initrd_end = 0; |
| 143 | } |
| 144 | |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 145 | show_boot_progress (15); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 146 | |
| 147 | #ifdef DEBUG |
| 148 | printf ("## Transferring control to Linux (at address %08lx) ...\n", |
| 149 | (ulong) theKernel); |
| 150 | #endif |
| 151 | |
| 152 | theKernel (commandline); |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 153 | } |