blob: b0cf2630cadef5feb87a77b2f9b7397ff5d828fa [file] [log] [blame]
wdenk2262cfe2002-11-18 00:14:45 +00001/*
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
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24#include <common.h>
25#include <command.h>
wdenk2262cfe2002-11-18 00:14:45 +000026#include <image.h>
27#include <zlib.h>
28#include <asm/byteorder.h>
29#include <asm/zimage.h>
30
wdenk8bde7f72003-06-27 21:31:46 +000031/*cmd_boot.c*/
32extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk2262cfe2002-11-18 00:14:45 +000033
34extern image_header_t header; /* from cmd_bootm.c */
35
wdenk2262cfe2002-11-18 00:14:45 +000036void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
37 ulong addr, ulong *len_ptr, int verify)
38{
wdenkea909b72002-11-21 23:11:29 +000039 void *base_ptr;
wdenk8bde7f72003-06-27 21:31:46 +000040
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010041 ulong len = 0;
wdenk2262cfe2002-11-18 00:14:45 +000042 ulong initrd_start, initrd_end;
43 ulong data;
44 image_header_t *hdr = &header;
wdenk8bde7f72003-06-27 21:31:46 +000045
wdenk2262cfe2002-11-18 00:14:45 +000046 /*
47 * Check if there is an initrd image
48 */
49 if (argc >= 3) {
50 addr = simple_strtoul(argv[2], NULL, 16);
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010051 hdr = (image_header_t *)addr;
wdenk8bde7f72003-06-27 21:31:46 +000052
wdenk2262cfe2002-11-18 00:14:45 +000053 printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
wdenk8bde7f72003-06-27 21:31:46 +000054
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010055 if (!image_check_magic (hdr)) {
wdenk2262cfe2002-11-18 00:14:45 +000056 printf ("Bad Magic Number\n");
57 do_reset (cmdtp, flag, argc, argv);
58 }
wdenk8bde7f72003-06-27 21:31:46 +000059
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010060 if (!image_check_hcrc (hdr)) {
wdenk2262cfe2002-11-18 00:14:45 +000061 printf ("Bad Header Checksum\n");
62 do_reset (cmdtp, flag, argc, argv);
63 }
wdenk8bde7f72003-06-27 21:31:46 +000064
wdenk2262cfe2002-11-18 00:14:45 +000065 print_image_hdr (hdr);
wdenk8bde7f72003-06-27 21:31:46 +000066
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010067 data = image_get_data (hdr);
68 len = image_get_data_size (hdr);
wdenk8bde7f72003-06-27 21:31:46 +000069
wdenk2262cfe2002-11-18 00:14:45 +000070 if (verify) {
wdenk2262cfe2002-11-18 00:14:45 +000071 printf (" Verifying Checksum ... ");
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010072 if (!image_check_dcrc (hdr)) {
wdenk2262cfe2002-11-18 00:14:45 +000073 printf ("Bad Data CRC\n");
74 do_reset (cmdtp, flag, argc, argv);
75 }
76 printf ("OK\n");
77 }
wdenk8bde7f72003-06-27 21:31:46 +000078
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010079 if (!image_check_os (hdr, IH_OS_LINUX) ||
80 !image_check_arch (hdr, IH_ARCH_I386) ||
81 !image_check_type (hdr, IH_TYPE_RAMDISK)) {
wdenk2262cfe2002-11-18 00:14:45 +000082 printf ("No Linux i386 Ramdisk Image\n");
83 do_reset (cmdtp, flag, argc, argv);
84 }
wdenk8bde7f72003-06-27 21:31:46 +000085
wdenk2262cfe2002-11-18 00:14:45 +000086 /*
87 * Now check if we have a multifile image
88 */
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010089 } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) {
90 ulong tail = image_to_cpu (len_ptr[0]) % 4;
wdenk2262cfe2002-11-18 00:14:45 +000091 int i;
wdenk8bde7f72003-06-27 21:31:46 +000092
wdenk2262cfe2002-11-18 00:14:45 +000093 /* skip kernel length and terminator */
94 data = (ulong)(&len_ptr[2]);
95 /* skip any additional image length fields */
96 for (i=1; len_ptr[i]; ++i)
97 data += 4;
98 /* add kernel length, and align */
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010099 data += image_to_cpu (len_ptr[0]);
wdenk2262cfe2002-11-18 00:14:45 +0000100 if (tail) {
101 data += 4 - tail;
102 }
wdenk8bde7f72003-06-27 21:31:46 +0000103
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100104 len = image_to_cpu (len_ptr[1]);
wdenk8bde7f72003-06-27 21:31:46 +0000105
wdenk2262cfe2002-11-18 00:14:45 +0000106 } else {
107 /*
108 * no initrd image
109 */
110 data = 0;
111 }
wdenk8bde7f72003-06-27 21:31:46 +0000112
wdenk2262cfe2002-11-18 00:14:45 +0000113#ifdef DEBUG
114 if (!data) {
115 printf ("No initrd\n");
116 }
117#endif
wdenk8bde7f72003-06-27 21:31:46 +0000118
wdenk2262cfe2002-11-18 00:14:45 +0000119 if (data) {
120 initrd_start = data;
121 initrd_end = initrd_start + len;
122 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
123 initrd_start, initrd_end);
124 memmove ((void *)initrd_start, (void *)data, len);
125 printf ("OK\n");
126 } else {
127 initrd_start = 0;
128 initrd_end = 0;
129 }
wdenk8bde7f72003-06-27 21:31:46 +0000130
Wolfgang Denke6446702006-07-21 11:30:18 +0200131 /* if multi-part image, we need to advance base ptr */
Marian Balakowicz15158972008-01-08 18:11:44 +0100132 if (image_check_type (&header, IH_TYPE_MULTI) && (len_ptr[1])) {
Wolfgang Denke6446702006-07-21 11:30:18 +0200133 int i;
134 for (i=0, addr+=sizeof(int); len_ptr[i++]; addr+=sizeof(int));
135 }
136
Marian Balakowicz15158972008-01-08 18:11:44 +0100137 base_ptr = load_zimage ((void*)addr + image_get_header_size (),
138 image_get_data_size (&header),
wdenk2262cfe2002-11-18 00:14:45 +0000139 initrd_start, initrd_end-initrd_start, 0);
140
141 if (NULL == base_ptr) {
142 printf ("## Kernel loading failed ...\n");
143 do_reset(cmdtp, flag, argc, argv);
wdenk8bde7f72003-06-27 21:31:46 +0000144
wdenk2262cfe2002-11-18 00:14:45 +0000145 }
wdenk8bde7f72003-06-27 21:31:46 +0000146
wdenk2262cfe2002-11-18 00:14:45 +0000147#ifdef DEBUG
148 printf ("## Transferring control to Linux (at address %08x) ...\n",
149 (u32)base_ptr);
150#endif
wdenk8bde7f72003-06-27 21:31:46 +0000151
wdenk2262cfe2002-11-18 00:14:45 +0000152 /* we assume that the kernel is in place */
153 printf("\nStarting kernel ...\n\n");
wdenk8bde7f72003-06-27 21:31:46 +0000154
wdenk2262cfe2002-11-18 00:14:45 +0000155 boot_zimage(base_ptr);
wdenk8bde7f72003-06-27 21:31:46 +0000156
wdenk2262cfe2002-11-18 00:14:45 +0000157}