[new uImage] Rename architecture specific bootm code files
[platform/kernel/u-boot.git] / lib_microblaze / bootm.c
1 /*
2  * (C) Copyright 2007 Michal Simek
3  * (C) Copyright 2004 Atmark Techno, Inc.
4  *
5  * Michal  SIMEK <monstr@monstr.eu>
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
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
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>
29 #include <image.h>
30 #include <zlib.h>
31 #include <asm/byteorder.h>
32
33 DECLARE_GLOBAL_DATA_PTR;
34
35 extern int do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]);
36
37 void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[],
38                      image_header_t *hdr, int verify)
39 {
40         int i;
41         ulong checksum;
42
43         ulong rd_data, rd_len;
44         ulong initrd_start, initrd_end;
45         image_header_t *rd_hdr;
46
47         /* First parameter is mapped to $r5 for kernel boot args */
48         void (*theKernel) (char *);
49         char *commandline = getenv ("bootargs");
50
51         theKernel = (void (*)(char *))image_get_ep (hdr);
52
53         /* Check if there is an initrd image */
54         if (argc >= 3) {
55                 show_boot_progress (9);
56
57                 rd_hdr = (image_header_t *)simple_strtoul (argv[2], NULL, 16);
58                 printf ("## Loading Ramdisk Image at %08lx ...\n", rd_hdr);
59
60                 if (!image_check_magic (rd_hdr)) {
61                         printf ("Bad Magic Number\n");
62                         show_boot_progress (-10);
63                         do_reset (cmdtp, flag, argc, argv);
64                 }
65
66                 if (!image_check_magic (rd_hdr)) {
67                         printf ("Bad Header Checksum\n");
68                         show_boot_progress (-11);
69                         do_reset (cmdtp, flag, argc, argv);
70                 }
71
72                 show_boot_progress (10);
73                 print_image_hdr (rd_hdr);
74
75                 rd_data = image_get_data (rd_hdr);
76                 rd_en = image_get_data_size (rd_hdr);
77
78                 if (verify) {
79                         printf ("   Verifying Checksum ... ");
80                         if (!image_check_dcrc (rd_hdr)) {
81                                 printf ("Bad Data CRC\n");
82                                 show_boot_progress (-12);
83                                 do_reset (cmdtp, flag, argc, argv);
84                         }
85                         printf ("OK\n");
86                 }
87
88                 show_boot_progress (11);
89
90                 if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
91                     !image_check_arch (rd_hdr, IH_ARCH_MICROBLAZE) ||
92                     !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
93                         printf ("No Linux Microblaze Ramdisk Image\n");
94                         show_boot_progress (-13);
95                         do_reset (cmdtp, flag, argc, argv);
96                 }
97
98                 /*
99                  * Now check if we have a multifile image
100                  */
101         } else if (image_check_type (hdr, IH_TYPE_MULTI)) {
102                 /*
103                  * Get second entry data start address and len
104                  */
105                 show_boot_progress (13);
106                 image_multi_getimg (hdr, 1, &rd_data, &rd_len);
107         } else {
108                 /*
109                  * no initrd image
110                  */
111                 show_boot_progress (14);
112
113                 rd_data = rd_len = 0;
114         }
115
116 #ifdef  DEBUG
117         if (!rd_data) {
118                 printf ("No initrd\n");
119         }
120 #endif
121
122         if (rd_data) {
123                 initrd_start = rd_data;
124                 initrd_end = initrd_start + rd_len;
125         } else {
126                 initrd_start = 0;
127                 initrd_end = 0;
128         }
129
130         show_boot_progress (15);
131
132 #ifdef DEBUG
133         printf ("## Transferring control to Linux (at address %08lx) ...\n",
134                 (ulong) theKernel);
135 #endif
136
137         theKernel (commandline);
138 }