Blame view

common/cmd_bootm.c 47.6 KB
47d1a6e1e   wdenk   Initial revision
1
  /*
ca95c9df0   Detlev Zundel   Add error checkin...
2
   * (C) Copyright 2000-2009
47d1a6e1e   wdenk   Initial revision
3
4
   * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
   *
1a4596601   Wolfgang Denk   Add GPL-2.0+ SPDX...
5
   * SPDX-License-Identifier:	GPL-2.0+
47d1a6e1e   wdenk   Initial revision
6
   */
b97a2a0a2   Marian Balakowicz   [new uImage] Defi...
7

47d1a6e1e   wdenk   Initial revision
8
9
10
11
12
13
  /*
   * Boot support
   */
  #include <common.h>
  #include <watchdog.h>
  #include <command.h>
47d1a6e1e   wdenk   Initial revision
14
15
  #include <image.h>
  #include <malloc.h>
a31e091ad   Jean-Christophe PLAGNIOL-VILLARD   rename include/zl...
16
  #include <u-boot/zlib.h>
c29fdfc1d   wdenk   Patch by Yuli Bar...
17
  #include <bzlib.h>
7f70e8530   wdenk   * Patch by David ...
18
  #include <environment.h>
4ed6552f7   Kumar Gala   [new uImage] Intr...
19
  #include <lmb.h>
49c3a861d   Kumar Gala   bootm: Add subcom...
20
  #include <linux/ctype.h>
47d1a6e1e   wdenk   Initial revision
21
  #include <asm/byteorder.h>
35e7b0f17   Simon Glass   sandbox: image: A...
22
  #include <asm/io.h>
5bf2766b4   Anatolij Gustschin   common/cmd_bootm....
23
  #include <linux/compiler.h>
8bde7f776   wdenk   * Code cleanup:
24

871a57bb8   Miao Yan   common/cmd_bootm:...
25
26
27
28
  #if defined(CONFIG_BOOTM_VXWORKS) && \
  	(defined(CONFIG_PPC) || defined(CONFIG_ARM))
  #include <vxworks.h>
  #endif
ebb86c4ec   Stefan Roese   cmd_bootm.c: Fix ...
29
  #if defined(CONFIG_CMD_USB)
3d71c81a9   Markus Klotzbücher   USB: shutdown USB...
30
31
  #include <usb.h>
  #endif
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
32
  #ifdef CONFIG_SYS_HUSH_PARSER
47d1a6e1e   wdenk   Initial revision
33
34
  #include <hush.h>
  #endif
54f9c8669   Kumar Gala   bootm: Set workin...
35
  #if defined(CONFIG_OF_LIBFDT)
54f9c8669   Kumar Gala   bootm: Set workin...
36
37
38
  #include <libfdt.h>
  #include <fdt_support.h>
  #endif
fc9c1727b   Luigi 'Comio' Mantellini   Add support for L...
39
  #ifdef CONFIG_LZMA
fc9c1727b   Luigi 'Comio' Mantellini   Add support for L...
40
  #include <lzma/LzmaTypes.h>
caf72ff32   Luigi 'Comio' Mantellini   Refresh LZMA-lib ...
41
  #include <lzma/LzmaDec.h>
fc9c1727b   Luigi 'Comio' Mantellini   Add support for L...
42
43
  #include <lzma/LzmaTools.h>
  #endif /* CONFIG_LZMA */
20dde48bc   Peter Korsgaard   add lzop decompre...
44
45
46
  #ifdef CONFIG_LZO
  #include <linux/lzo.h>
  #endif /* CONFIG_LZO */
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
47
  DECLARE_GLOBAL_DATA_PTR;
228f29ac6   wdenk   * Improve log buf...
48

6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
49
50
  #ifndef CONFIG_SYS_BOOTM_LEN
  #define CONFIG_SYS_BOOTM_LEN	0x800000	/* use 8MByte as default max gunzip size */
2abbe0754   wdenk   * Patch by Nicola...
51
  #endif
321359f20   Marian Balakowicz   [new uImage] Move...
52
53
  #ifdef CONFIG_BZIP2
  extern void bz_internal_error(int);
47d1a6e1e   wdenk   Initial revision
54
  #endif
baa26db41   Jon Loeliger   common/cmd_[af]*:...
55
  #if defined(CONFIG_CMD_IMI)
712fbcf38   Stephen Warren   checkpatch whites...
56
  static int image_info(unsigned long addr);
47d1a6e1e   wdenk   Initial revision
57
  #endif
27b207fd0   wdenk   * Implement new m...
58

baa26db41   Jon Loeliger   common/cmd_[af]*:...
59
  #if defined(CONFIG_CMD_IMLS)
27b207fd0   wdenk   * Implement new m...
60
  #include <flash.h>
ca5def3f3   Stefan Roese   cfi_flash: Simpli...
61
  #include <mtd/cfi_flash.h>
e6f2e9023   Marian Balakowicz   Added support for...
62
  extern flash_info_t flash_info[]; /* info for FLASH chips */
8fdf1e0f6   Vipin Kumar   imls: Add support...
63
64
65
  #endif
  
  #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
712fbcf38   Stephen Warren   checkpatch whites...
66
  static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
27b207fd0   wdenk   * Implement new m...
67
  #endif
8fdf1e0f6   Vipin Kumar   imls: Add support...
68
69
  #include <linux/err.h>
  #include <nand.h>
be2e5a09e   Joe Hershberger   Allow u-boot to b...
70
  #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
712fbcf38   Stephen Warren   checkpatch whites...
71
  static void fixup_silent_linux(void);
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
72
  #endif
47d1a6e1e   wdenk   Initial revision
73

c5cbe1e29   Simon Glass   bootm: Reinstate ...
74
75
  static int do_bootm_standalone(int flag, int argc, char * const argv[],
  			       bootm_headers_t *images);
35e7b0f17   Simon Glass   sandbox: image: A...
76
  static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
712fbcf38   Stephen Warren   checkpatch whites...
77
78
  				char * const argv[], bootm_headers_t *images,
  				ulong *os_data, ulong *os_len);
47d1a6e1e   wdenk   Initial revision
79
80
81
82
83
84
85
86
  
  /*
   *  Continue booting an OS image; caller already has:
   *  - copied image header to global variable `header'
   *  - checked header magic number, checksums (both header & image),
   *  - verified image architecture (PPC) and type (KERNEL or MULTI),
   *  - loaded (first part of) image to header load address,
   *  - disabled interrupts.
983c72f47   Simon Glass   Clarify bootm OS ...
87
   *
35fc84fa1   Simon Glass   Refactor the boot...
88
   * @flag: Flags indicating what to do (BOOTM_STATE_...)
983c72f47   Simon Glass   Clarify bootm OS ...
89
90
91
92
93
94
95
   * @argc: Number of arguments. Note that the arguments are shifted down
   *	 so that 0 is the first argument not processed by U-Boot, and
   *	 argc is adjusted accordingly. This avoids confusion as to how
   *	 many arguments are available for the OS.
   * @images: Pointers to os/initrd/fdt
   * @return 1 on error. On success the OS boots so this function does
   * not return.
47d1a6e1e   wdenk   Initial revision
96
   */
712fbcf38   Stephen Warren   checkpatch whites...
97
  typedef int boot_os_fn(int flag, int argc, char * const argv[],
983c72f47   Simon Glass   Clarify bootm OS ...
98
  			bootm_headers_t *images);
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
99

b1d0db180   Kumar Gala   bootm: Added CONF...
100
  #ifdef CONFIG_BOOTM_LINUX
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
101
  extern boot_os_fn do_bootm_linux;
b1d0db180   Kumar Gala   bootm: Added CONF...
102
103
  #endif
  #ifdef CONFIG_BOOTM_NETBSD
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
104
  static boot_os_fn do_bootm_netbsd;
b1d0db180   Kumar Gala   bootm: Added CONF...
105
  #endif
f13e7b2e9   Marian Balakowicz   [new uImage] Clea...
106
  #if defined(CONFIG_LYNXKDI)
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
107
  static boot_os_fn do_bootm_lynxkdi;
712fbcf38   Stephen Warren   checkpatch whites...
108
  extern void lynxkdi_boot(image_header_t *);
47d1a6e1e   wdenk   Initial revision
109
  #endif
b1d0db180   Kumar Gala   bootm: Added CONF...
110
  #ifdef CONFIG_BOOTM_RTEMS
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
111
  static boot_os_fn do_bootm_rtems;
b1d0db180   Kumar Gala   bootm: Added CONF...
112
  #endif
3df619579   Torkel Lundgren   Add support for o...
113
114
115
  #if defined(CONFIG_BOOTM_OSE)
  static boot_os_fn do_bootm_ose;
  #endif
04d414090   Steven Stallion   image: Add suppor...
116
117
118
  #if defined(CONFIG_BOOTM_PLAN9)
  static boot_os_fn do_bootm_plan9;
  #endif
871a57bb8   Miao Yan   common/cmd_bootm:...
119
120
  #if defined(CONFIG_BOOTM_VXWORKS) && \
  	(defined(CONFIG_PPC) || defined(CONFIG_ARM))
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
121
  static boot_os_fn do_bootm_vxworks;
17ab52fef   Miao Yan   common/cmd_bootm....
122
123
  #endif
  #if defined(CONFIG_CMD_ELF)
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
124
  static boot_os_fn do_bootm_qnxelf;
712fbcf38   Stephen Warren   checkpatch whites...
125
126
  int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
  int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
902531788   Jon Loeliger   common/: Remove l...
127
  #endif
f5ed9e390   Peter Tyser   Add support for b...
128
129
130
  #if defined(CONFIG_INTEGRITY)
  static boot_os_fn do_bootm_integrity;
  #endif
47d1a6e1e   wdenk   Initial revision
131

0008555f4   Mike Frysinger   bootm: mark local...
132
  static boot_os_fn *boot_os[] = {
c5cbe1e29   Simon Glass   bootm: Reinstate ...
133
  	[IH_OS_U_BOOT] = do_bootm_standalone,
b1d0db180   Kumar Gala   bootm: Added CONF...
134
  #ifdef CONFIG_BOOTM_LINUX
be0831593   Kumar Gala   bootm: Move to us...
135
  	[IH_OS_LINUX] = do_bootm_linux,
b1d0db180   Kumar Gala   bootm: Added CONF...
136
137
  #endif
  #ifdef CONFIG_BOOTM_NETBSD
be0831593   Kumar Gala   bootm: Move to us...
138
  	[IH_OS_NETBSD] = do_bootm_netbsd,
b1d0db180   Kumar Gala   bootm: Added CONF...
139
  #endif
be0831593   Kumar Gala   bootm: Move to us...
140
141
142
  #ifdef CONFIG_LYNXKDI
  	[IH_OS_LYNXOS] = do_bootm_lynxkdi,
  #endif
b1d0db180   Kumar Gala   bootm: Added CONF...
143
  #ifdef CONFIG_BOOTM_RTEMS
be0831593   Kumar Gala   bootm: Move to us...
144
  	[IH_OS_RTEMS] = do_bootm_rtems,
b1d0db180   Kumar Gala   bootm: Added CONF...
145
  #endif
3df619579   Torkel Lundgren   Add support for o...
146
147
148
  #if defined(CONFIG_BOOTM_OSE)
  	[IH_OS_OSE] = do_bootm_ose,
  #endif
04d414090   Steven Stallion   image: Add suppor...
149
150
151
  #if defined(CONFIG_BOOTM_PLAN9)
  	[IH_OS_PLAN9] = do_bootm_plan9,
  #endif
871a57bb8   Miao Yan   common/cmd_bootm:...
152
153
  #if defined(CONFIG_BOOTM_VXWORKS) && \
  	(defined(CONFIG_PPC) || defined(CONFIG_ARM))
be0831593   Kumar Gala   bootm: Move to us...
154
  	[IH_OS_VXWORKS] = do_bootm_vxworks,
17ab52fef   Miao Yan   common/cmd_bootm....
155
156
  #endif
  #if defined(CONFIG_CMD_ELF)
be0831593   Kumar Gala   bootm: Move to us...
157
158
159
160
161
162
  	[IH_OS_QNX] = do_bootm_qnxelf,
  #endif
  #ifdef CONFIG_INTEGRITY
  	[IH_OS_INTEGRITY] = do_bootm_integrity,
  #endif
  };
dee17768d   Simon Schwarz   removed static fr...
163
  bootm_headers_t images;		/* pointers to os/initrd/fdt images */
15940c9af   Stefan Roese   Change max size o...
164

3dfad40a0   Kumar Gala   Add ability for a...
165
  /* Allow for arch specific config before we boot */
088f1b199   Kim Phillips   common/cmd_*.c: s...
166
  static void __arch_preboot_os(void)
3dfad40a0   Kumar Gala   Add ability for a...
167
168
169
170
  {
  	/* please define platform specific arch_preboot_os() */
  }
  void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
476af299b   Mike Frysinger   image: push defau...
171
  #define IH_INITRD_ARCH IH_ARCH_DEFAULT
47d1a6e1e   wdenk   Initial revision
172

a16028da6   Mike Frysinger   lmb: only force o...
173
  #ifdef CONFIG_LMB
44f074c77   Marek Vasut   BOOT: Add "bootz"...
174
175
  static void boot_start_lmb(bootm_headers_t *images)
  {
391fd93ab   Becky Bruce   Change lmb to use...
176
177
  	ulong		mem_start;
  	phys_size_t	mem_size;
47d1a6e1e   wdenk   Initial revision
178

44f074c77   Marek Vasut   BOOT: Add "bootz"...
179
  	lmb_init(&images->lmb);
47d1a6e1e   wdenk   Initial revision
180

d3f2fa0d2   Kumar Gala   [new uImage] Prov...
181
182
  	mem_start = getenv_bootm_low();
  	mem_size = getenv_bootm_size();
47d1a6e1e   wdenk   Initial revision
183

44f074c77   Marek Vasut   BOOT: Add "bootz"...
184
  	lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size);
47d1a6e1e   wdenk   Initial revision
185

44f074c77   Marek Vasut   BOOT: Add "bootz"...
186
187
188
  	arch_lmb_reserve(&images->lmb);
  	board_lmb_reserve(&images->lmb);
  }
a16028da6   Mike Frysinger   lmb: only force o...
189
  #else
35cf5fe51   Marek Vasut   LMB: Fix undefine...
190
  #define lmb_reserve(lmb, base, size)
44f074c77   Marek Vasut   BOOT: Add "bootz"...
191
  static inline void boot_start_lmb(bootm_headers_t *images) { }
a16028da6   Mike Frysinger   lmb: only force o...
192
  #endif
a16028da6   Mike Frysinger   lmb: only force o...
193

54841ab50   Wolfgang Denk   Make sure that ar...
194
  static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
a16028da6   Mike Frysinger   lmb: only force o...
195
  {
712fbcf38   Stephen Warren   checkpatch whites...
196
197
  	memset((void *)&images, 0, sizeof(images));
  	images.verify = getenv_yesno("verify");
a16028da6   Mike Frysinger   lmb: only force o...
198

44f074c77   Marek Vasut   BOOT: Add "bootz"...
199
  	boot_start_lmb(&images);
47d1a6e1e   wdenk   Initial revision
200

573f14fe4   Simon Glass   bootstage: Plumb ...
201
  	bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start");
35fc84fa1   Simon Glass   Refactor the boot...
202
203
204
205
206
207
208
209
210
  	images.state = BOOTM_STATE_START;
  
  	return 0;
  }
  
  static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
  			 char * const argv[])
  {
  	const void *os_hdr;
573f14fe4   Simon Glass   bootstage: Plumb ...
211

5cf746c30   Marian Balakowicz   [new uImage] Move...
212
  	/* get kernel image header, start address and length */
712fbcf38   Stephen Warren   checkpatch whites...
213
  	os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
396f635b8   Kumar Gala   bootm: refactor i...
214
215
  			&images, &images.os.image_start, &images.os.image_len);
  	if (images.os.image_len == 0) {
712fbcf38   Stephen Warren   checkpatch whites...
216
217
  		puts("ERROR: can't get kernel image!
  ");
47d1a6e1e   wdenk   Initial revision
218
  		return 1;
bccae9039   Wolfgang Denk   Fix booting from ...
219
  	}
bccae9039   Wolfgang Denk   Fix booting from ...
220

d5934ad77   Marian Balakowicz   [new uImage] Add ...
221
  	/* get image parameters */
712fbcf38   Stephen Warren   checkpatch whites...
222
  	switch (genimg_get_format(os_hdr)) {
d5934ad77   Marian Balakowicz   [new uImage] Add ...
223
  	case IMAGE_FORMAT_LEGACY:
712fbcf38   Stephen Warren   checkpatch whites...
224
225
226
  		images.os.type = image_get_type(os_hdr);
  		images.os.comp = image_get_comp(os_hdr);
  		images.os.os = image_get_os(os_hdr);
bccae9039   Wolfgang Denk   Fix booting from ...
227

712fbcf38   Stephen Warren   checkpatch whites...
228
229
  		images.os.end = image_get_image_end(os_hdr);
  		images.os.load = image_get_load(os_hdr);
d5934ad77   Marian Balakowicz   [new uImage] Add ...
230
231
232
  		break;
  #if defined(CONFIG_FIT)
  	case IMAGE_FORMAT_FIT:
712fbcf38   Stephen Warren   checkpatch whites...
233
  		if (fit_image_get_type(images.fit_hdr_os,
396f635b8   Kumar Gala   bootm: refactor i...
234
  					images.fit_noffset_os, &images.os.type)) {
712fbcf38   Stephen Warren   checkpatch whites...
235
236
  			puts("Can't get image type!
  ");
770605e4f   Simon Glass   bootstage: Replac...
237
  			bootstage_error(BOOTSTAGE_ID_FIT_TYPE);
6986a3856   Marian Balakowicz   [new uImage] Add ...
238
239
  			return 1;
  		}
47d1a6e1e   wdenk   Initial revision
240

712fbcf38   Stephen Warren   checkpatch whites...
241
  		if (fit_image_get_comp(images.fit_hdr_os,
396f635b8   Kumar Gala   bootm: refactor i...
242
  					images.fit_noffset_os, &images.os.comp)) {
712fbcf38   Stephen Warren   checkpatch whites...
243
244
  			puts("Can't get image compression!
  ");
770605e4f   Simon Glass   bootstage: Replac...
245
  			bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION);
6986a3856   Marian Balakowicz   [new uImage] Add ...
246
247
  			return 1;
  		}
47d1a6e1e   wdenk   Initial revision
248

712fbcf38   Stephen Warren   checkpatch whites...
249
  		if (fit_image_get_os(images.fit_hdr_os,
396f635b8   Kumar Gala   bootm: refactor i...
250
  					images.fit_noffset_os, &images.os.os)) {
712fbcf38   Stephen Warren   checkpatch whites...
251
252
  			puts("Can't get image OS!
  ");
770605e4f   Simon Glass   bootstage: Replac...
253
  			bootstage_error(BOOTSTAGE_ID_FIT_OS);
47d1a6e1e   wdenk   Initial revision
254
255
  			return 1;
  		}
47d1a6e1e   wdenk   Initial revision
256

712fbcf38   Stephen Warren   checkpatch whites...
257
  		images.os.end = fit_get_end(images.fit_hdr_os);
6986a3856   Marian Balakowicz   [new uImage] Add ...
258

712fbcf38   Stephen Warren   checkpatch whites...
259
  		if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
396f635b8   Kumar Gala   bootm: refactor i...
260
  					&images.os.load)) {
712fbcf38   Stephen Warren   checkpatch whites...
261
262
  			puts("Can't get image load address!
  ");
770605e4f   Simon Glass   bootstage: Replac...
263
  			bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR);
6986a3856   Marian Balakowicz   [new uImage] Add ...
264
  			return 1;
b13fb01a6   wdenk   * Fix parameter p...
265
266
  		}
  		break;
d5934ad77   Marian Balakowicz   [new uImage] Add ...
267
268
  #endif
  	default:
712fbcf38   Stephen Warren   checkpatch whites...
269
270
  		puts("ERROR: unknown image format type!
  ");
47d1a6e1e   wdenk   Initial revision
271
272
  		return 1;
  	}
d5934ad77   Marian Balakowicz   [new uImage] Add ...
273

c160a9544   Kumar Gala   bootm: refactor e...
274
275
  	/* find kernel entry point */
  	if (images.legacy_hdr_valid) {
712fbcf38   Stephen Warren   checkpatch whites...
276
  		images.ep = image_get_ep(&images.legacy_hdr_os_copy);
c160a9544   Kumar Gala   bootm: refactor e...
277
278
  #if defined(CONFIG_FIT)
  	} else if (images.fit_uname_os) {
35fc84fa1   Simon Glass   Refactor the boot...
279
  		int ret;
712fbcf38   Stephen Warren   checkpatch whites...
280
  		ret = fit_image_get_entry(images.fit_hdr_os,
c19d13b03   Simon Glass   arm: Refactor boo...
281
  					  images.fit_noffset_os, &images.ep);
c160a9544   Kumar Gala   bootm: refactor e...
282
  		if (ret) {
712fbcf38   Stephen Warren   checkpatch whites...
283
284
  			puts("Can't get entry point property!
  ");
c160a9544   Kumar Gala   bootm: refactor e...
285
286
287
288
  			return 1;
  		}
  #endif
  	} else {
712fbcf38   Stephen Warren   checkpatch whites...
289
290
  		puts("Could not find kernel entry point!
  ");
c160a9544   Kumar Gala   bootm: refactor e...
291
292
  		return 1;
  	}
b9b50e89d   Stephen Warren   image: Implement ...
293
294
295
296
  	if (images.os.type == IH_TYPE_KERNEL_NOLOAD) {
  		images.os.load = images.os.image_start;
  		images.ep += images.os.load;
  	}
35fc84fa1   Simon Glass   Refactor the boot...
297
298
299
300
  	images.os.start = (ulong)os_hdr;
  
  	return 0;
  }
225fd8c5d   Tom Rini   cmd_bootm.c: Make...
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
  static int bootm_find_ramdisk(int flag, int argc, char * const argv[])
  {
  	int ret;
  
  	/* find ramdisk */
  	ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
  			       &images.rd_start, &images.rd_end);
  	if (ret) {
  		puts("Ramdisk image is corrupt or invalid
  ");
  		return 1;
  	}
  
  	return 0;
  }
  
  #if defined(CONFIG_OF_LIBFDT)
  static int bootm_find_fdt(int flag, int argc, char * const argv[])
35fc84fa1   Simon Glass   Refactor the boot...
319
320
  {
  	int ret;
225fd8c5d   Tom Rini   cmd_bootm.c: Make...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
  	/* find flattened device tree */
  	ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images,
  			   &images.ft_addr, &images.ft_len);
  	if (ret) {
  		puts("Could not find a valid device tree
  ");
  		return 1;
  	}
  
  	set_working_fdt_addr(images.ft_addr);
  
  	return 0;
  }
  #endif
  
  static int bootm_find_other(cmd_tbl_t *cmdtp, int flag, int argc,
  			    char * const argv[])
  {
24de2f4be   Heiko Schocher   bootm, linux: fix...
339
  	if (((images.os.type == IH_TYPE_KERNEL) ||
b9b50e89d   Stephen Warren   image: Implement ...
340
  	     (images.os.type == IH_TYPE_KERNEL_NOLOAD) ||
24de2f4be   Heiko Schocher   bootm, linux: fix...
341
  	     (images.os.type == IH_TYPE_MULTI)) &&
871a57bb8   Miao Yan   common/cmd_bootm:...
342
343
  	    (images.os.os == IH_OS_LINUX ||
  		 images.os.os == IH_OS_VXWORKS)) {
225fd8c5d   Tom Rini   cmd_bootm.c: Make...
344
  		if (bootm_find_ramdisk(flag, argc, argv))
c4f9419c6   Kumar Gala   bootm: refactor r...
345
  			return 1;
06a09918f   Kumar Gala   bootm: refactor f...
346
347
  
  #if defined(CONFIG_OF_LIBFDT)
225fd8c5d   Tom Rini   cmd_bootm.c: Make...
348
  		if (bootm_find_fdt(flag, argc, argv))
06a09918f   Kumar Gala   bootm: refactor f...
349
  			return 1;
06a09918f   Kumar Gala   bootm: refactor f...
350
  #endif
c4f9419c6   Kumar Gala   bootm: refactor r...
351
  	}
396f635b8   Kumar Gala   bootm: refactor i...
352
353
  	return 0;
  }
3d71c81a9   Markus Klotzbücher   USB: shutdown USB...
354

396f635b8   Kumar Gala   bootm: refactor i...
355
356
357
  #define BOOTM_ERR_RESET		-1
  #define BOOTM_ERR_OVERLAP	-2
  #define BOOTM_ERR_UNIMPLEMENTED	-3
d366438d8   Tom Rini   cmd_bootm.c: Corr...
358
359
  static int bootm_load_os(bootm_headers_t *images, unsigned long *load_end,
  		int boot_progress)
396f635b8   Kumar Gala   bootm: refactor i...
360
  {
d366438d8   Tom Rini   cmd_bootm.c: Corr...
361
  	image_info_t os = images->os;
396f635b8   Kumar Gala   bootm: refactor i...
362
363
364
365
366
367
  	uint8_t comp = os.comp;
  	ulong load = os.load;
  	ulong blob_start = os.start;
  	ulong blob_end = os.end;
  	ulong image_start = os.image_start;
  	ulong image_len = os.image_len;
5bf2766b4   Anatolij Gustschin   common/cmd_bootm....
368
  	__maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
d510859be   Stephen Warren   image: Don't dete...
369
  	int no_overlap = 0;
aed161e5f   Simon Glass   sandbox: Adjust b...
370
  	void *load_buf, *image_buf;
60fdc5f2f   Matthias Weisser   LZMA and LZO caus...
371
372
373
  #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
  	int ret;
  #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
3d71c81a9   Markus Klotzbücher   USB: shutdown USB...
374

712fbcf38   Stephen Warren   checkpatch whites...
375
  	const char *type_name = genimg_get_type_name(os.type);
c7de829c7   wdenk   * Patch by Thomas...
376

315c0ace7   Kees Cook   bootm: allow corr...
377
  	load_buf = map_sysmem(load, unc_len);
aed161e5f   Simon Glass   sandbox: Adjust b...
378
  	image_buf = map_sysmem(image_start, image_len);
d5934ad77   Marian Balakowicz   [new uImage] Add ...
379
  	switch (comp) {
47d1a6e1e   wdenk   Initial revision
380
  	case IH_COMP_NONE:
02cf34597   Lei Wen   bootm: replace bl...
381
  		if (load == blob_start || load == image_start) {
712fbcf38   Stephen Warren   checkpatch whites...
382
  			printf("   XIP %s ... ", type_name);
d510859be   Stephen Warren   image: Don't dete...
383
  			no_overlap = 1;
47d1a6e1e   wdenk   Initial revision
384
  		} else {
712fbcf38   Stephen Warren   checkpatch whites...
385
  			printf("   Loading %s ... ", type_name);
aed161e5f   Simon Glass   sandbox: Adjust b...
386
  			memmove_wd(load_buf, image_buf, image_len, CHUNKSZ);
47d1a6e1e   wdenk   Initial revision
387
  		}
396f635b8   Kumar Gala   bootm: refactor i...
388
  		*load_end = load + image_len;
47d1a6e1e   wdenk   Initial revision
389
  		break;
44431cabb   Mike Frysinger   gzip/zlib: make f...
390
  #ifdef CONFIG_GZIP
47d1a6e1e   wdenk   Initial revision
391
  	case IH_COMP_GZIP:
712fbcf38   Stephen Warren   checkpatch whites...
392
  		printf("   Uncompressing %s ... ", type_name);
aed161e5f   Simon Glass   sandbox: Adjust b...
393
  		if (gunzip(load_buf, unc_len, image_buf, &image_len) != 0) {
712fbcf38   Stephen Warren   checkpatch whites...
394
395
396
  			puts("GUNZIP: uncompress, out-of-mem or overwrite "
  				"error - must RESET board to recover
  ");
396f635b8   Kumar Gala   bootm: refactor i...
397
  			if (boot_progress)
770605e4f   Simon Glass   bootstage: Replac...
398
  				bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
396f635b8   Kumar Gala   bootm: refactor i...
399
  			return BOOTM_ERR_RESET;
47d1a6e1e   wdenk   Initial revision
400
  		}
7582438c2   Marian Balakowicz   [new uImage] Retu...
401

396f635b8   Kumar Gala   bootm: refactor i...
402
  		*load_end = load + image_len;
47d1a6e1e   wdenk   Initial revision
403
  		break;
44431cabb   Mike Frysinger   gzip/zlib: make f...
404
  #endif /* CONFIG_GZIP */
c29fdfc1d   wdenk   Patch by Yuli Bar...
405
406
  #ifdef CONFIG_BZIP2
  	case IH_COMP_BZIP2:
712fbcf38   Stephen Warren   checkpatch whites...
407
  		printf("   Uncompressing %s ... ", type_name);
5653fc335   wdenk   * Patch by Yuli B...
408
409
410
411
412
  		/*
  		 * If we've got less than 4 MB of malloc() space,
  		 * use slower decompression algorithm which requires
  		 * at most 2300 KB of memory.
  		 */
aed161e5f   Simon Glass   sandbox: Adjust b...
413
414
415
  		int i = BZ2_bzBuffToBuffDecompress(load_buf, &unc_len,
  			image_buf, image_len,
  			CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
c29fdfc1d   wdenk   Patch by Yuli Bar...
416
  		if (i != BZ_OK) {
712fbcf38   Stephen Warren   checkpatch whites...
417
  			printf("BUNZIP2: uncompress or overwrite error %d "
2682ce8a4   Marian Balakowicz   [new uImage] More...
418
419
  				"- must RESET board to recover
  ", i);
396f635b8   Kumar Gala   bootm: refactor i...
420
  			if (boot_progress)
770605e4f   Simon Glass   bootstage: Replac...
421
  				bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
396f635b8   Kumar Gala   bootm: refactor i...
422
  			return BOOTM_ERR_RESET;
c29fdfc1d   wdenk   Patch by Yuli Bar...
423
  		}
7582438c2   Marian Balakowicz   [new uImage] Retu...
424

396f635b8   Kumar Gala   bootm: refactor i...
425
  		*load_end = load + unc_len;
c29fdfc1d   wdenk   Patch by Yuli Bar...
426
427
  		break;
  #endif /* CONFIG_BZIP2 */
fc9c1727b   Luigi 'Comio' Mantellini   Add support for L...
428
  #ifdef CONFIG_LZMA
78e1e8467   Mike Frysinger   bootm: fix pointe...
429
430
  	case IH_COMP_LZMA: {
  		SizeT lzma_len = unc_len;
712fbcf38   Stephen Warren   checkpatch whites...
431
  		printf("   Uncompressing %s ... ", type_name);
fc9c1727b   Luigi 'Comio' Mantellini   Add support for L...
432

aed161e5f   Simon Glass   sandbox: Adjust b...
433
434
  		ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len,
  					       image_buf, image_len);
78e1e8467   Mike Frysinger   bootm: fix pointe...
435
  		unc_len = lzma_len;
caf72ff32   Luigi 'Comio' Mantellini   Refresh LZMA-lib ...
436
  		if (ret != SZ_OK) {
712fbcf38   Stephen Warren   checkpatch whites...
437
  			printf("LZMA: uncompress or overwrite error %d "
fc9c1727b   Luigi 'Comio' Mantellini   Add support for L...
438
439
  				"- must RESET board to recover
  ", ret);
770605e4f   Simon Glass   bootstage: Replac...
440
  			bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
fc9c1727b   Luigi 'Comio' Mantellini   Add support for L...
441
442
443
444
  			return BOOTM_ERR_RESET;
  		}
  		*load_end = load + unc_len;
  		break;
78e1e8467   Mike Frysinger   bootm: fix pointe...
445
  	}
fc9c1727b   Luigi 'Comio' Mantellini   Add support for L...
446
  #endif /* CONFIG_LZMA */
20dde48bc   Peter Korsgaard   add lzop decompre...
447
  #ifdef CONFIG_LZO
628af1790   Simon Glass   sandbox: Correct ...
448
449
  	case IH_COMP_LZO: {
  		size_t size;
712fbcf38   Stephen Warren   checkpatch whites...
450
  		printf("   Uncompressing %s ... ", type_name);
20dde48bc   Peter Korsgaard   add lzop decompre...
451

628af1790   Simon Glass   sandbox: Correct ...
452
  		ret = lzop_decompress(image_buf, image_len, load_buf, &size);
20dde48bc   Peter Korsgaard   add lzop decompre...
453
  		if (ret != LZO_E_OK) {
712fbcf38   Stephen Warren   checkpatch whites...
454
  			printf("LZO: uncompress or overwrite error %d "
20dde48bc   Peter Korsgaard   add lzop decompre...
455
456
457
  			      "- must RESET board to recover
  ", ret);
  			if (boot_progress)
770605e4f   Simon Glass   bootstage: Replac...
458
  				bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
20dde48bc   Peter Korsgaard   add lzop decompre...
459
460
  			return BOOTM_ERR_RESET;
  		}
628af1790   Simon Glass   sandbox: Correct ...
461
  		*load_end = load + size;
20dde48bc   Peter Korsgaard   add lzop decompre...
462
  		break;
628af1790   Simon Glass   sandbox: Correct ...
463
  	}
20dde48bc   Peter Korsgaard   add lzop decompre...
464
  #endif /* CONFIG_LZO */
47d1a6e1e   wdenk   Initial revision
465
  	default:
712fbcf38   Stephen Warren   checkpatch whites...
466
467
  		printf("Unimplemented compression type %d
  ", comp);
396f635b8   Kumar Gala   bootm: refactor i...
468
  		return BOOTM_ERR_UNIMPLEMENTED;
47d1a6e1e   wdenk   Initial revision
469
  	}
99ffccbd3   Diana CRACIUN   Flush cache after...
470
471
  
  	flush_cache(load, (*load_end - load) * sizeof(ulong));
712fbcf38   Stephen Warren   checkpatch whites...
472
473
474
475
  	puts("OK
  ");
  	debug("   kernel loaded at 0x%08lx, end = 0x%08lx
  ", load, *load_end);
770605e4f   Simon Glass   bootstage: Replac...
476
  	bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED);
47d1a6e1e   wdenk   Initial revision
477

d510859be   Stephen Warren   image: Don't dete...
478
  	if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) {
712fbcf38   Stephen Warren   checkpatch whites...
479
480
481
482
483
484
  		debug("images.os.start = 0x%lX, images.os.end = 0x%lx
  ",
  			blob_start, blob_end);
  		debug("images.os.load = 0x%lx, load_end = 0x%lx
  ", load,
  			*load_end);
47d1a6e1e   wdenk   Initial revision
485

d366438d8   Tom Rini   cmd_bootm.c: Corr...
486
487
488
489
490
491
492
493
494
495
496
497
498
  		/* Check what type of image this is. */
  		if (images->legacy_hdr_valid) {
  			if (image_get_type(&images->legacy_hdr_os_copy)
  					== IH_TYPE_MULTI)
  				puts("WARNING: legacy format multi component image overwritten
  ");
  			return BOOTM_ERR_OVERLAP;
  		} else {
  			puts("ERROR: new format image overwritten - must RESET the board to recover
  ");
  			bootstage_error(BOOTSTAGE_ID_OVERWRITTEN);
  			return BOOTM_ERR_RESET;
  		}
396f635b8   Kumar Gala   bootm: refactor i...
499
500
501
502
  	}
  
  	return 0;
  }
c5cbe1e29   Simon Glass   bootm: Reinstate ...
503
504
  static int do_bootm_standalone(int flag, int argc, char * const argv[],
  			       bootm_headers_t *images)
f97ec30bb   Detlev Zundel   Re-add support fo...
505
506
  {
  	char  *s;
54841ab50   Wolfgang Denk   Make sure that ar...
507
  	int   (*appl)(int, char * const []);
f97ec30bb   Detlev Zundel   Re-add support fo...
508
509
510
  
  	/* Don't start if "autostart" is set to "no" */
  	if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
c5cbe1e29   Simon Glass   bootm: Reinstate ...
511
  		setenv_hex("filesize", images->os.image_len);
f97ec30bb   Detlev Zundel   Re-add support fo...
512
513
  		return 0;
  	}
9c89614d3   Christian Eggers   common: Remove in...
514
515
  	appl = (int (*)(int, char * const []))images->ep;
  	appl(argc, argv);
f97ec30bb   Detlev Zundel   Re-add support fo...
516
517
  	return 0;
  }
49c3a861d   Kumar Gala   bootm: Add subcom...
518
519
  /* we overload the cmd field with our state machine info instead of a
   * function pointer */
f74d9bd2a   Frans Meulenbroeks   cmd_bootm.c: made...
520
  static cmd_tbl_t cmd_bootm_sub[] = {
49c3a861d   Kumar Gala   bootm: Add subcom...
521
522
  	U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
  	U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
fca43cc80   John Rigby   boot: change some...
523
  #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
49c3a861d   Kumar Gala   bootm: Add subcom...
524
525
526
527
528
  	U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
  #endif
  #ifdef CONFIG_OF_LIBFDT
  	U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
  #endif
49c3a861d   Kumar Gala   bootm: Add subcom...
529
  	U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
224c90d10   Peter Tyser   bootm: Fix help m...
530
  	U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
49c3a861d   Kumar Gala   bootm: Add subcom...
531
  	U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
d0ae31eb0   Simon Glass   Add a 'fake' go c...
532
  	U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""),
49c3a861d   Kumar Gala   bootm: Add subcom...
533
534
  	U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
  };
35fc84fa1   Simon Glass   Refactor the boot...
535
  static int boot_selected_os(int argc, char * const argv[], int state,
5ff0d0832   Simon Glass   bootm: Disable in...
536
  		bootm_headers_t *images, boot_os_fn *boot_fn)
35fc84fa1   Simon Glass   Refactor the boot...
537
  {
35fc84fa1   Simon Glass   Refactor the boot...
538
539
  	arch_preboot_os();
  	boot_fn(state, argc, argv, images);
c5cbe1e29   Simon Glass   bootm: Reinstate ...
540
541
542
543
  
  	/* Stand-alone may return when 'autostart' is 'no' */
  	if (images->os.type == IH_TYPE_STANDALONE ||
  	    state == BOOTM_STATE_OS_FAKE_GO) /* We expect to return */
d0ae31eb0   Simon Glass   Add a 'fake' go c...
544
  		return 0;
35fc84fa1   Simon Glass   Refactor the boot...
545
546
547
548
549
550
551
552
553
554
  	bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
  #ifdef DEBUG
  	puts("
  ## Control returned to monitor - resetting...
  ");
  #endif
  	return BOOTM_ERR_RESET;
  }
  
  /**
385501d38   Simon Glass   bootm: Disable in...
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
   * bootm_disable_interrupts() - Disable interrupts in preparation for load/boot
   *
   * @return interrupt flag (0 if interrupts were disabled, non-zero if they were
   *	enabled)
   */
  static ulong bootm_disable_interrupts(void)
  {
  	ulong iflag;
  
  	/*
  	 * We have reached the point of no return: we are going to
  	 * overwrite all exception vector code, so we cannot easily
  	 * recover from any failures any more...
  	 */
  	iflag = disable_interrupts();
  #ifdef CONFIG_NETCONSOLE
  	/* Stop the ethernet stack if NetConsole could have left it up */
  	eth_halt();
8094972d5   Frederic Leroy   Fix loading freez...
573
  	eth_unregister(eth_get_dev());
385501d38   Simon Glass   bootm: Disable in...
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
  #endif
  
  #if defined(CONFIG_CMD_USB)
  	/*
  	 * turn off USB to prevent the host controller from writing to the
  	 * SDRAM while Linux is booting. This could happen (at least for OHCI
  	 * controller), because the HCCA (Host Controller Communication Area)
  	 * lies within the SDRAM and the host controller writes continously to
  	 * this area (as busmaster!). The HccaFrameNumber is for example
  	 * updated every 1 ms within the HCCA structure in SDRAM! For more
  	 * details see the OpenHCI specification.
  	 */
  	usb_stop();
  #endif
  	return iflag;
  }
  
  /**
35fc84fa1   Simon Glass   Refactor the boot...
592
593
594
595
596
597
598
599
   * Execute selected states of the bootm command.
   *
   * Note the arguments to this state must be the first argument, Any 'bootm'
   * or sub-command arguments must have already been taken.
   *
   * Note that if states contains more than one flag it MUST contain
   * BOOTM_STATE_START, since this handles and consumes the command line args.
   *
d366438d8   Tom Rini   cmd_bootm.c: Corr...
600
601
602
603
   * Also note that aside from boot_os_fn functions and bootm_load_os no other
   * functions we store the return value of in 'ret' may use a negative return
   * value, without special handling.
   *
35fc84fa1   Simon Glass   Refactor the boot...
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
   * @param cmdtp		Pointer to bootm command table entry
   * @param flag		Command flags (CMD_FLAG_...)
   * @param argc		Number of subcommand arguments (0 = no arguments)
   * @param argv		Arguments
   * @param states	Mask containing states to run (BOOTM_STATE_...)
   * @param images	Image header information
   * @param boot_progress 1 to show boot progress, 0 to not do this
   * @return 0 if ok, something else on error. Some errors will cause this
   *	function to perform a reboot! If states contains BOOTM_STATE_OS_GO
   *	then the intent is to boot an OS, so this function will not return
   *	unless the image type is standalone.
   */
  static int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc,
  		char * const argv[], int states, bootm_headers_t *images,
  		int boot_progress)
  {
  	boot_os_fn *boot_fn;
  	ulong iflag = 0;
a26913f32   Simon Glass   bootm: Require bo...
622
  	int ret = 0, need_boot_fn;
35fc84fa1   Simon Glass   Refactor the boot...
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
  
  	images->state |= states;
  
  	/*
  	 * Work through the states and see how far we get. We stop on
  	 * any error.
  	 */
  	if (states & BOOTM_STATE_START)
  		ret = bootm_start(cmdtp, flag, argc, argv);
  
  	if (!ret && (states & BOOTM_STATE_FINDOS))
  		ret = bootm_find_os(cmdtp, flag, argc, argv);
  
  	if (!ret && (states & BOOTM_STATE_FINDOTHER)) {
  		ret = bootm_find_other(cmdtp, flag, argc, argv);
  		argc = 0;	/* consume the args */
  	}
  
  	/* Load the OS */
  	if (!ret && (states & BOOTM_STATE_LOADOS)) {
  		ulong load_end;
385501d38   Simon Glass   bootm: Disable in...
644
  		iflag = bootm_disable_interrupts();
d366438d8   Tom Rini   cmd_bootm.c: Corr...
645
  		ret = bootm_load_os(images, &load_end, 0);
d366438d8   Tom Rini   cmd_bootm.c: Corr...
646
  		if (ret == 0)
35fc84fa1   Simon Glass   Refactor the boot...
647
648
  			lmb_reserve(&images->lmb, images->os.load,
  				    (load_end - images->os.load));
970150a16   Tom Rini   cmd_bootm.c: Re-o...
649
650
  		else if (ret && ret != BOOTM_ERR_OVERLAP)
  			goto err;
d366438d8   Tom Rini   cmd_bootm.c: Corr...
651
652
  		else if (ret == BOOTM_ERR_OVERLAP)
  			ret = 0;
bd4a3997f   Paul B. Henson   bootm: fix condit...
653
  #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
576aacdb9   Simon Glass   bootm: Move fixup...
654
655
656
  		if (images->os.os == IH_OS_LINUX)
  			fixup_silent_linux();
  #endif
35fc84fa1   Simon Glass   Refactor the boot...
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
  	}
  
  	/* Relocate the ramdisk */
  #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  	if (!ret && (states & BOOTM_STATE_RAMDISK)) {
  		ulong rd_len = images->rd_end - images->rd_start;
  
  		ret = boot_ramdisk_high(&images->lmb, images->rd_start,
  			rd_len, &images->initrd_start, &images->initrd_end);
  		if (!ret) {
  			setenv_hex("initrd_start", images->initrd_start);
  			setenv_hex("initrd_end", images->initrd_end);
  		}
  	}
  #endif
  #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
  	if (!ret && (states & BOOTM_STATE_FDT)) {
  		boot_fdt_add_mem_rsv_regions(&images->lmb, images->ft_addr);
  		ret = boot_relocate_fdt(&images->lmb, &images->ft_addr,
  					&images->ft_len);
  	}
  #endif
  
  	/* From now on, we need the OS boot function */
  	if (ret)
  		return ret;
  	boot_fn = boot_os[images->os.os];
a26913f32   Simon Glass   bootm: Require bo...
684
685
686
687
  	need_boot_fn = states & (BOOTM_STATE_OS_CMDLINE |
  			BOOTM_STATE_OS_BD_T | BOOTM_STATE_OS_PREP |
  			BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO);
  	if (boot_fn == NULL && need_boot_fn) {
35fc84fa1   Simon Glass   Refactor the boot...
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
  		if (iflag)
  			enable_interrupts();
  		printf("ERROR: booting os '%s' (%d) is not supported
  ",
  		       genimg_get_os_name(images->os.os), images->os.os);
  		bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS);
  		return 1;
  	}
  
  	/* Call various other states that are not generally used */
  	if (!ret && (states & BOOTM_STATE_OS_CMDLINE))
  		ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, images);
  	if (!ret && (states & BOOTM_STATE_OS_BD_T))
  		ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
  	if (!ret && (states & BOOTM_STATE_OS_PREP))
  		ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images);
d0ae31eb0   Simon Glass   Add a 'fake' go c...
704
705
706
707
708
709
  #ifdef CONFIG_TRACE
  	/* Pretend to run the OS, then run a user command */
  	if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) {
  		char *cmd_list = getenv("fakegocmd");
  
  		ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_FAKE_GO,
5ff0d0832   Simon Glass   bootm: Disable in...
710
  				images, boot_fn);
d0ae31eb0   Simon Glass   Add a 'fake' go c...
711
712
713
714
  		if (!ret && cmd_list)
  			ret = run_command_list(cmd_list, -1, flag);
  	}
  #endif
b7a1d1346   Simon Glass   bootm: Handle err...
715
716
717
718
719
720
721
  
  	/* Check for unsupported subcommand. */
  	if (ret) {
  		puts("subcommand not supported
  ");
  		return ret;
  	}
35fc84fa1   Simon Glass   Refactor the boot...
722
  	/* Now run the OS! We hope this doesn't return */
b7a1d1346   Simon Glass   bootm: Handle err...
723
  	if (!ret && (states & BOOTM_STATE_OS_GO))
35fc84fa1   Simon Glass   Refactor the boot...
724
  		ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_GO,
5ff0d0832   Simon Glass   bootm: Disable in...
725
  				images, boot_fn);
35fc84fa1   Simon Glass   Refactor the boot...
726
727
  
  	/* Deal with any fallout */
d366438d8   Tom Rini   cmd_bootm.c: Corr...
728
  err:
35fc84fa1   Simon Glass   Refactor the boot...
729
730
  	if (iflag)
  		enable_interrupts();
d366438d8   Tom Rini   cmd_bootm.c: Corr...
731
732
733
734
735
  
  	if (ret == BOOTM_ERR_UNIMPLEMENTED)
  		bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL);
  	else if (ret == BOOTM_ERR_RESET)
  		do_reset(cmdtp, flag, argc, argv);
35fc84fa1   Simon Glass   Refactor the boot...
736
737
738
  
  	return ret;
  }
088f1b199   Kim Phillips   common/cmd_*.c: s...
739
  static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
712fbcf38   Stephen Warren   checkpatch whites...
740
  			char * const argv[])
49c3a861d   Kumar Gala   bootm: Add subcom...
741
742
  {
  	int ret = 0;
6d6f12363   Simon Glass   sandbox: Add boot...
743
  	long state;
49c3a861d   Kumar Gala   bootm: Add subcom...
744
  	cmd_tbl_t *c;
49c3a861d   Kumar Gala   bootm: Add subcom...
745

983c72f47   Simon Glass   Clarify bootm OS ...
746
747
  	c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
  	argc--; argv++;
49c3a861d   Kumar Gala   bootm: Add subcom...
748
749
  
  	if (c) {
6d6f12363   Simon Glass   sandbox: Add boot...
750
  		state = (long)c->cmd;
983c72f47   Simon Glass   Clarify bootm OS ...
751
  		if (state == BOOTM_STATE_START)
35fc84fa1   Simon Glass   Refactor the boot...
752
  			state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER;
47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
753
754
  	} else {
  		/* Unrecognized command */
4c12eeb8b   Simon Glass   Convert cmd_usage...
755
  		return CMD_RET_USAGE;
49c3a861d   Kumar Gala   bootm: Add subcom...
756
  	}
35fc84fa1   Simon Glass   Refactor the boot...
757
  	if (state != BOOTM_STATE_START && images.state >= state) {
712fbcf38   Stephen Warren   checkpatch whites...
758
759
  		printf("Trying to execute a command out of order
  ");
4c12eeb8b   Simon Glass   Convert cmd_usage...
760
  		return CMD_RET_USAGE;
49c3a861d   Kumar Gala   bootm: Add subcom...
761
  	}
35fc84fa1   Simon Glass   Refactor the boot...
762
  	ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0);
49c3a861d   Kumar Gala   bootm: Add subcom...
763
764
765
  
  	return ret;
  }
396f635b8   Kumar Gala   bootm: refactor i...
766
767
768
  /*******************************************************************/
  /* bootm - boot application image from image in memory */
  /*******************************************************************/
be0831593   Kumar Gala   bootm: Move to us...
769

712fbcf38   Stephen Warren   checkpatch whites...
770
  int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
396f635b8   Kumar Gala   bootm: refactor i...
771
  {
2e5167cca   Wolfgang Denk   Replace CONFIG_RE...
772
  #ifdef CONFIG_NEEDS_MANUAL_RELOC
521af04d8   Peter Tyser   Conditionally per...
773
  	static int relocated = 0;
be0831593   Kumar Gala   bootm: Move to us...
774

be0831593   Kumar Gala   bootm: Move to us...
775
776
  	if (!relocated) {
  		int i;
58bd77db9   Daniel Schwierzeck   bootm: relocate n...
777
778
  
  		/* relocate boot function table */
be0831593   Kumar Gala   bootm: Move to us...
779
  		for (i = 0; i < ARRAY_SIZE(boot_os); i++)
ca95c9df0   Detlev Zundel   Add error checkin...
780
781
  			if (boot_os[i] != NULL)
  				boot_os[i] += gd->reloc_off;
58bd77db9   Daniel Schwierzeck   bootm: relocate n...
782
783
784
785
  
  		/* relocate names of sub-command table */
  		for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
  			cmd_bootm_sub[i].name += gd->reloc_off;
be0831593   Kumar Gala   bootm: Move to us...
786
787
  		relocated = 1;
  	}
521af04d8   Peter Tyser   Conditionally per...
788
  #endif
396f635b8   Kumar Gala   bootm: refactor i...
789

49c3a861d   Kumar Gala   bootm: Add subcom...
790
  	/* determine if we have a sub command */
983c72f47   Simon Glass   Clarify bootm OS ...
791
792
  	argc--; argv++;
  	if (argc > 0) {
49c3a861d   Kumar Gala   bootm: Add subcom...
793
  		char *endp;
983c72f47   Simon Glass   Clarify bootm OS ...
794
795
  		simple_strtoul(argv[0], &endp, 16);
  		/* endp pointing to NULL means that argv[0] was just a
49c3a861d   Kumar Gala   bootm: Add subcom...
796
797
798
799
800
801
802
803
804
805
  		 * valid number, pass it along to the normal bootm processing
  		 *
  		 * If endp is ':' or '#' assume a FIT identifier so pass
  		 * along for normal processing.
  		 *
  		 * Right now we assume the first arg should never be '-'
  		 */
  		if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
  			return do_bootm_subcommand(cmdtp, flag, argc, argv);
  	}
35fc84fa1   Simon Glass   Refactor the boot...
806
807
  	return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START |
  		BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER |
3d187b392   Tom Rini   cmd_bootm.c: Only...
808
809
810
811
  		BOOTM_STATE_LOADOS |
  #if defined(CONFIG_PPC) || defined(CONFIG_MIPS)
  		BOOTM_STATE_OS_CMDLINE |
  #endif
5c427e49c   Paul Burton   bootm: use BOOTM_...
812
813
  		BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
  		BOOTM_STATE_OS_GO, &images, 1);
47d1a6e1e   wdenk   Initial revision
814
  }
67d668bf9   Mike Frysinger   autostart: unify ...
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
  int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
  {
  	const char *ep = getenv("autostart");
  
  	if (ep && !strcmp(ep, "yes")) {
  		char *local_args[2];
  		local_args[0] = (char *)cmd;
  		local_args[1] = NULL;
  		printf("Automatic boot of image at addr 0x%08lX ...
  ", load_addr);
  		return do_bootm(cmdtp, 0, 1, local_args);
  	}
  
  	return 0;
  }
5cf746c30   Marian Balakowicz   [new uImage] Move...
830
  /**
9a4daad0a   Marian Balakowicz   [new uImage] Upda...
831
832
833
   * image_get_kernel - verify legacy format kernel image
   * @img_addr: in RAM address of the legacy format image to be verified
   * @verify: data CRC verification flag
5cf746c30   Marian Balakowicz   [new uImage] Move...
834
   *
9a4daad0a   Marian Balakowicz   [new uImage] Upda...
835
836
   * image_get_kernel() verifies legacy image integrity and returns pointer to
   * legacy image header if image verification was completed successfully.
5cf746c30   Marian Balakowicz   [new uImage] Move...
837
838
   *
   * returns:
9a4daad0a   Marian Balakowicz   [new uImage] Upda...
839
840
   *     pointer to a legacy image header if valid image was found
   *     otherwise return NULL
5cf746c30   Marian Balakowicz   [new uImage] Move...
841
   */
712fbcf38   Stephen Warren   checkpatch whites...
842
  static image_header_t *image_get_kernel(ulong img_addr, int verify)
f72da3406   wdenk   Added config opti...
843
  {
1efd43601   Marian Balakowicz   [new uImage] Add ...
844
  	image_header_t *hdr = (image_header_t *)img_addr;
f72da3406   wdenk   Added config opti...
845

1efd43601   Marian Balakowicz   [new uImage] Add ...
846
  	if (!image_check_magic(hdr)) {
712fbcf38   Stephen Warren   checkpatch whites...
847
848
  		puts("Bad Magic Number
  ");
770605e4f   Simon Glass   bootstage: Replac...
849
  		bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC);
1efd43601   Marian Balakowicz   [new uImage] Add ...
850
851
  		return NULL;
  	}
770605e4f   Simon Glass   bootstage: Replac...
852
  	bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER);
f72da3406   wdenk   Added config opti...
853

712fbcf38   Stephen Warren   checkpatch whites...
854
855
856
  	if (!image_check_hcrc(hdr)) {
  		puts("Bad Header Checksum
  ");
770605e4f   Simon Glass   bootstage: Replac...
857
  		bootstage_error(BOOTSTAGE_ID_CHECK_HEADER);
1efd43601   Marian Balakowicz   [new uImage] Add ...
858
859
  		return NULL;
  	}
770605e4f   Simon Glass   bootstage: Replac...
860
  	bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM);
712fbcf38   Stephen Warren   checkpatch whites...
861
  	image_print_contents(hdr);
1efd43601   Marian Balakowicz   [new uImage] Add ...
862
863
  
  	if (verify) {
712fbcf38   Stephen Warren   checkpatch whites...
864
865
866
867
  		puts("   Verifying Checksum ... ");
  		if (!image_check_dcrc(hdr)) {
  			printf("Bad Data CRC
  ");
770605e4f   Simon Glass   bootstage: Replac...
868
  			bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM);
1efd43601   Marian Balakowicz   [new uImage] Add ...
869
  			return NULL;
f72da3406   wdenk   Added config opti...
870
  		}
712fbcf38   Stephen Warren   checkpatch whites...
871
872
  		puts("OK
  ");
f72da3406   wdenk   Added config opti...
873
  	}
770605e4f   Simon Glass   bootstage: Replac...
874
  	bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH);
f72da3406   wdenk   Added config opti...
875

712fbcf38   Stephen Warren   checkpatch whites...
876
877
878
  	if (!image_check_target_arch(hdr)) {
  		printf("Unsupported Architecture 0x%x
  ", image_get_arch(hdr));
770605e4f   Simon Glass   bootstage: Replac...
879
  		bootstage_error(BOOTSTAGE_ID_CHECK_ARCH);
1efd43601   Marian Balakowicz   [new uImage] Add ...
880
881
882
  		return NULL;
  	}
  	return hdr;
f72da3406   wdenk   Added config opti...
883
  }
f72da3406   wdenk   Added config opti...
884

1efd43601   Marian Balakowicz   [new uImage] Add ...
885
  /**
9a4daad0a   Marian Balakowicz   [new uImage] Upda...
886
   * boot_get_kernel - find kernel image
1efd43601   Marian Balakowicz   [new uImage] Add ...
887
888
889
   * @os_data: pointer to a ulong variable, will hold os data start address
   * @os_len: pointer to a ulong variable, will hold os data length
   *
9a4daad0a   Marian Balakowicz   [new uImage] Upda...
890
   * boot_get_kernel() tries to find a kernel image, verifies its integrity
1efd43601   Marian Balakowicz   [new uImage] Add ...
891
892
893
894
895
896
   * and locates kernel data.
   *
   * returns:
   *     pointer to image header if valid image was found, plus kernel start
   *     address and length, otherwise NULL
   */
35e7b0f17   Simon Glass   sandbox: image: A...
897
  static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
712fbcf38   Stephen Warren   checkpatch whites...
898
899
  		char * const argv[], bootm_headers_t *images, ulong *os_data,
  		ulong *os_len)
5cf746c30   Marian Balakowicz   [new uImage] Move...
900
901
902
  {
  	image_header_t	*hdr;
  	ulong		img_addr;
35e7b0f17   Simon Glass   sandbox: image: A...
903
  	const void *buf;
d5934ad77   Marian Balakowicz   [new uImage] Add ...
904
  #if defined(CONFIG_FIT)
d5934ad77   Marian Balakowicz   [new uImage] Add ...
905
906
  	const char	*fit_uname_config = NULL;
  	const char	*fit_uname_kernel = NULL;
6986a3856   Marian Balakowicz   [new uImage] Add ...
907
  	int		os_noffset;
d5934ad77   Marian Balakowicz   [new uImage] Add ...
908
  #endif
56f94be3e   wdenk   * Add support for...
909

d5934ad77   Marian Balakowicz   [new uImage] Add ...
910
  	/* find out kernel image address */
983c72f47   Simon Glass   Clarify bootm OS ...
911
  	if (argc < 1) {
5cf746c30   Marian Balakowicz   [new uImage] Move...
912
  		img_addr = load_addr;
712fbcf38   Stephen Warren   checkpatch whites...
913
914
  		debug("*  kernel: default image load address = 0x%08lx
  ",
d5934ad77   Marian Balakowicz   [new uImage] Add ...
915
916
  				load_addr);
  #if defined(CONFIG_FIT)
983c72f47   Simon Glass   Clarify bootm OS ...
917
  	} else if (fit_parse_conf(argv[0], load_addr, &img_addr,
d5934ad77   Marian Balakowicz   [new uImage] Add ...
918
  							&fit_uname_config)) {
712fbcf38   Stephen Warren   checkpatch whites...
919
920
  		debug("*  kernel: config '%s' from image at 0x%08lx
  ",
d5934ad77   Marian Balakowicz   [new uImage] Add ...
921
  				fit_uname_config, img_addr);
983c72f47   Simon Glass   Clarify bootm OS ...
922
  	} else if (fit_parse_subimage(argv[0], load_addr, &img_addr,
d5934ad77   Marian Balakowicz   [new uImage] Add ...
923
  							&fit_uname_kernel)) {
712fbcf38   Stephen Warren   checkpatch whites...
924
925
  		debug("*  kernel: subimage '%s' from image at 0x%08lx
  ",
d5934ad77   Marian Balakowicz   [new uImage] Add ...
926
927
  				fit_uname_kernel, img_addr);
  #endif
5cf746c30   Marian Balakowicz   [new uImage] Move...
928
  	} else {
983c72f47   Simon Glass   Clarify bootm OS ...
929
  		img_addr = simple_strtoul(argv[0], NULL, 16);
712fbcf38   Stephen Warren   checkpatch whites...
930
931
  		debug("*  kernel: cmdline image address = 0x%08lx
  ", img_addr);
5cf746c30   Marian Balakowicz   [new uImage] Move...
932
  	}
47d1a6e1e   wdenk   Initial revision
933

770605e4f   Simon Glass   bootstage: Replac...
934
  	bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
56f94be3e   wdenk   * Add support for...
935

fff888a19   Marian Balakowicz   [new uImage] Add ...
936
  	/* copy from dataflash if needed */
712fbcf38   Stephen Warren   checkpatch whites...
937
  	img_addr = genimg_get_image(img_addr);
5cf746c30   Marian Balakowicz   [new uImage] Move...
938

d5934ad77   Marian Balakowicz   [new uImage] Add ...
939
  	/* check image type, for FIT images get FIT kernel node */
6986a3856   Marian Balakowicz   [new uImage] Add ...
940
  	*os_data = *os_len = 0;
35e7b0f17   Simon Glass   sandbox: image: A...
941
942
  	buf = map_sysmem(img_addr, 0);
  	switch (genimg_get_format(buf)) {
d5934ad77   Marian Balakowicz   [new uImage] Add ...
943
  	case IMAGE_FORMAT_LEGACY:
712fbcf38   Stephen Warren   checkpatch whites...
944
945
  		printf("## Booting kernel from Legacy Image at %08lx ...
  ",
6986a3856   Marian Balakowicz   [new uImage] Add ...
946
  				img_addr);
712fbcf38   Stephen Warren   checkpatch whites...
947
  		hdr = image_get_kernel(img_addr, images->verify);
1efd43601   Marian Balakowicz   [new uImage] Add ...
948
  		if (!hdr)
d5934ad77   Marian Balakowicz   [new uImage] Add ...
949
  			return NULL;
770605e4f   Simon Glass   bootstage: Replac...
950
  		bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE);
d5934ad77   Marian Balakowicz   [new uImage] Add ...
951

6986a3856   Marian Balakowicz   [new uImage] Add ...
952
  		/* get os_data and os_len */
712fbcf38   Stephen Warren   checkpatch whites...
953
  		switch (image_get_type(hdr)) {
d5934ad77   Marian Balakowicz   [new uImage] Add ...
954
  		case IH_TYPE_KERNEL:
b9b50e89d   Stephen Warren   image: Implement ...
955
  		case IH_TYPE_KERNEL_NOLOAD:
712fbcf38   Stephen Warren   checkpatch whites...
956
957
  			*os_data = image_get_data(hdr);
  			*os_len = image_get_data_size(hdr);
d5934ad77   Marian Balakowicz   [new uImage] Add ...
958
959
  			break;
  		case IH_TYPE_MULTI:
712fbcf38   Stephen Warren   checkpatch whites...
960
  			image_multi_getimg(hdr, 0, os_data, os_len);
d5934ad77   Marian Balakowicz   [new uImage] Add ...
961
  			break;
f97ec30bb   Detlev Zundel   Re-add support fo...
962
  		case IH_TYPE_STANDALONE:
712fbcf38   Stephen Warren   checkpatch whites...
963
964
  			*os_data = image_get_data(hdr);
  			*os_len = image_get_data_size(hdr);
f97ec30bb   Detlev Zundel   Re-add support fo...
965
  			break;
d5934ad77   Marian Balakowicz   [new uImage] Add ...
966
  		default:
712fbcf38   Stephen Warren   checkpatch whites...
967
968
969
  			printf("Wrong Image Type for %s command
  ",
  				cmdtp->name);
770605e4f   Simon Glass   bootstage: Replac...
970
  			bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE);
d5934ad77   Marian Balakowicz   [new uImage] Add ...
971
972
  			return NULL;
  		}
cb1c48969   Marian Balakowicz   Restore the abili...
973
974
  
  		/*
712fbcf38   Stephen Warren   checkpatch whites...
975
976
  		 * copy image header to allow for image overwrites during
  		 * kernel decompression.
cb1c48969   Marian Balakowicz   Restore the abili...
977
  		 */
712fbcf38   Stephen Warren   checkpatch whites...
978
979
  		memmove(&images->legacy_hdr_os_copy, hdr,
  			sizeof(image_header_t));
cb1c48969   Marian Balakowicz   Restore the abili...
980
981
  
  		/* save pointer to image header */
d5934ad77   Marian Balakowicz   [new uImage] Add ...
982
  		images->legacy_hdr_os = hdr;
47d1a6e1e   wdenk   Initial revision
983

cb1c48969   Marian Balakowicz   Restore the abili...
984
  		images->legacy_hdr_valid = 1;
770605e4f   Simon Glass   bootstage: Replac...
985
  		bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
5cf746c30   Marian Balakowicz   [new uImage] Move...
986
  		break;
d5934ad77   Marian Balakowicz   [new uImage] Add ...
987
988
  #if defined(CONFIG_FIT)
  	case IMAGE_FORMAT_FIT:
4651800d5   Simon Glass   image: Use fit_im...
989
990
  		os_noffset = fit_image_load(images, FIT_KERNEL_PROP,
  				img_addr,
f320a4d84   Simon Glass   bootm: Use select...
991
  				&fit_uname_kernel, &fit_uname_config,
4651800d5   Simon Glass   image: Use fit_im...
992
993
994
995
  				IH_ARCH_DEFAULT, IH_TYPE_KERNEL,
  				BOOTSTAGE_ID_FIT_KERNEL_START,
  				FIT_LOAD_IGNORED, os_data, os_len);
  		if (os_noffset < 0)
6986a3856   Marian Balakowicz   [new uImage] Add ...
996
  			return NULL;
47d1a6e1e   wdenk   Initial revision
997

4651800d5   Simon Glass   image: Use fit_im...
998
  		images->fit_hdr_os = map_sysmem(img_addr, 0);
6986a3856   Marian Balakowicz   [new uImage] Add ...
999
  		images->fit_uname_os = fit_uname_kernel;
f320a4d84   Simon Glass   bootm: Use select...
1000
  		images->fit_uname_cfg = fit_uname_config;
3dfe11014   Marian Balakowicz   [new uImage] Add ...
1001
  		images->fit_noffset_os = os_noffset;
6986a3856   Marian Balakowicz   [new uImage] Add ...
1002
  		break;
9c4c5ae3e   Jon Loeliger   * Patch by Jon Lo...
1003
  #endif
5cf746c30   Marian Balakowicz   [new uImage] Move...
1004
  	default:
712fbcf38   Stephen Warren   checkpatch whites...
1005
1006
  		printf("Wrong Image Format for %s command
  ", cmdtp->name);
770605e4f   Simon Glass   bootstage: Replac...
1007
  		bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO);
5cf746c30   Marian Balakowicz   [new uImage] Move...
1008
  		return NULL;
47d1a6e1e   wdenk   Initial revision
1009
  	}
712fbcf38   Stephen Warren   checkpatch whites...
1010
1011
  	debug("   kernel data at 0x%08lx, len = 0x%08lx (%ld)
  ",
6986a3856   Marian Balakowicz   [new uImage] Add ...
1012
  			*os_data, *os_len, *os_len);
47d1a6e1e   wdenk   Initial revision
1013

35e7b0f17   Simon Glass   sandbox: image: A...
1014
  	return buf;
5cf746c30   Marian Balakowicz   [new uImage] Move...
1015
  }
98a9c4d46   Matthew McClintock   * Modify bootm co...
1016

088f1b199   Kim Phillips   common/cmd_*.c: s...
1017
1018
  #ifdef CONFIG_SYS_LONGHELP
  static char bootm_help_text[] =
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1019
1020
1021
1022
1023
1024
1025
  	"[addr [arg ...]]
      - boot application image stored in memory
  "
  	"\tpassing arguments 'arg ...'; when booting a Linux kernel,
  "
  	"\t'arg' can be the address of an initrd image
  "
4a2ad5ff6   Marian Balakowicz   [new uImage] Remo...
1026
  #if defined(CONFIG_OF_LIBFDT)
98a9c4d46   Matthew McClintock   * Modify bootm co...
1027
1028
  	"\tWhen booting a Linux kernel which requires a flat device-tree
  "
5441f61a3   Detlev Zundel   Fix two typos.
1029
1030
  	"\ta third argument is required which is the address of the
  "
98a9c4d46   Matthew McClintock   * Modify bootm co...
1031
1032
1033
1034
1035
1036
  	"\tdevice-tree blob. To boot that kernel without an initrd image,
  "
  	"\tuse a '-' for the second argument. If you do not pass a third
  "
  	"\ta bd_info struct will be passed instead
  "
98a9c4d46   Matthew McClintock   * Modify bootm co...
1037
  #endif
6986a3856   Marian Balakowicz   [new uImage] Add ...
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
  #if defined(CONFIG_FIT)
  	"\t
  For the new multi component uImage format (FIT) addresses
  "
  	"\tmust be extened to include component or configuration unit name:
  "
  	"\taddr:<subimg_uname> - direct component image specification
  "
  	"\taddr#<conf_uname>   - configuration specification
  "
  	"\tUse iminfo command to get the list of existing component
  "
  	"\timages and configurations.
  "
  #endif
49c3a861d   Kumar Gala   bootm: Add subcom...
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
  	"
  Sub-commands to do part of the bootm sequence.  The sub-commands "
  	"must be
  "
  	"issued in the order below (it's ok to not issue all sub-commands):
  "
  	"\tstart [addr [arg ...]]
  "
  	"\tloados  - load OS image
  "
59af76d9c   Daniel Schwierzeck   bootm: fix condit...
1063
  #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
49c3a861d   Kumar Gala   bootm: Add subcom...
1064
1065
1066
1067
1068
1069
1070
  	"\tramdisk - relocate initrd, set env initrd_start/initrd_end
  "
  #endif
  #if defined(CONFIG_OF_LIBFDT)
  	"\tfdt     - relocate flat device tree
  "
  #endif
49c3a861d   Kumar Gala   bootm: Add subcom...
1071
1072
  	"\tcmdline - OS specific command line processing/setup
  "
224c90d10   Peter Tyser   bootm: Fix help m...
1073
1074
  	"\tbdt     - OS specific bd_t processing
  "
49c3a861d   Kumar Gala   bootm: Add subcom...
1075
1076
  	"\tprep    - OS specific prep before relocation or go
  "
088f1b199   Kim Phillips   common/cmd_*.c: s...
1077
1078
1079
1080
1081
1082
  	"\tgo      - start OS";
  #endif
  
  U_BOOT_CMD(
  	bootm,	CONFIG_SYS_MAXARGS,	1,	do_bootm,
  	"boot application image from memory", bootm_help_text
8bde7f776   wdenk   * Code cleanup:
1083
  );
47d1a6e1e   wdenk   Initial revision
1084

1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1085
1086
1087
  /*******************************************************************/
  /* bootd - boot default image */
  /*******************************************************************/
baa26db41   Jon Loeliger   common/cmd_[af]*:...
1088
  #if defined(CONFIG_CMD_BOOTD)
712fbcf38   Stephen Warren   checkpatch whites...
1089
  int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
47d1a6e1e   wdenk   Initial revision
1090
1091
  {
  	int rcode = 0;
47d1a6e1e   wdenk   Initial revision
1092

530715323   Simon Glass   Stop using builti...
1093
  	if (run_command(getenv("bootcmd"), flag) < 0)
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1094
  		rcode = 1;
47d1a6e1e   wdenk   Initial revision
1095
1096
  	return rcode;
  }
47d1a6e1e   wdenk   Initial revision
1097

0d4983930   wdenk   Patch by Kenneth ...
1098
  U_BOOT_CMD(
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1099
  	boot,	1,	1,	do_bootd,
2fb2604d5   Peter Tyser   Command usage cle...
1100
  	"boot default, i.e., run 'bootcmd'",
a89c33db9   Wolfgang Denk   General help mess...
1101
  	""
9d2b18a0f   wdenk   Rewrite command l...
1102
  );
47d1a6e1e   wdenk   Initial revision
1103

9d2b18a0f   wdenk   Rewrite command l...
1104
  /* keep old command name "bootd" for backward compatibility */
0d4983930   wdenk   Patch by Kenneth ...
1105
  U_BOOT_CMD(
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1106
  	bootd, 1,	1,	do_bootd,
2fb2604d5   Peter Tyser   Command usage cle...
1107
  	"boot default, i.e., run 'bootcmd'",
a89c33db9   Wolfgang Denk   General help mess...
1108
  	""
8bde7f776   wdenk   * Code cleanup:
1109
  );
47d1a6e1e   wdenk   Initial revision
1110

47d1a6e1e   wdenk   Initial revision
1111
  #endif
47d1a6e1e   wdenk   Initial revision
1112

47d1a6e1e   wdenk   Initial revision
1113

1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1114
1115
1116
  /*******************************************************************/
  /* iminfo - print header info for a requested image */
  /*******************************************************************/
baa26db41   Jon Loeliger   common/cmd_[af]*:...
1117
  #if defined(CONFIG_CMD_IMI)
088f1b199   Kim Phillips   common/cmd_*.c: s...
1118
  static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
47d1a6e1e   wdenk   Initial revision
1119
1120
1121
  {
  	int	arg;
  	ulong	addr;
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1122
  	int	rcode = 0;
47d1a6e1e   wdenk   Initial revision
1123

47d1a6e1e   wdenk   Initial revision
1124
  	if (argc < 2) {
712fbcf38   Stephen Warren   checkpatch whites...
1125
  		return image_info(load_addr);
47d1a6e1e   wdenk   Initial revision
1126
  	}
47d1a6e1e   wdenk   Initial revision
1127

1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1128
  	for (arg = 1; arg < argc; ++arg) {
712fbcf38   Stephen Warren   checkpatch whites...
1129
1130
  		addr = simple_strtoul(argv[arg], NULL, 16);
  		if (image_info(addr) != 0)
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1131
  			rcode = 1;
47d1a6e1e   wdenk   Initial revision
1132
1133
1134
  	}
  	return rcode;
  }
47d1a6e1e   wdenk   Initial revision
1135

712fbcf38   Stephen Warren   checkpatch whites...
1136
  static int image_info(ulong addr)
47d1a6e1e   wdenk   Initial revision
1137
  {
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1138
  	void *hdr = (void *)addr;
47d1a6e1e   wdenk   Initial revision
1139

712fbcf38   Stephen Warren   checkpatch whites...
1140
1141
1142
  	printf("
  ## Checking Image at %08lx ...
  ", addr);
47d1a6e1e   wdenk   Initial revision
1143

712fbcf38   Stephen Warren   checkpatch whites...
1144
  	switch (genimg_get_format(hdr)) {
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1145
  	case IMAGE_FORMAT_LEGACY:
712fbcf38   Stephen Warren   checkpatch whites...
1146
1147
1148
1149
1150
  		puts("   Legacy image found
  ");
  		if (!image_check_magic(hdr)) {
  			puts("   Bad Magic Number
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1151
1152
  			return 1;
  		}
47d1a6e1e   wdenk   Initial revision
1153

712fbcf38   Stephen Warren   checkpatch whites...
1154
1155
1156
  		if (!image_check_hcrc(hdr)) {
  			puts("   Bad Header Checksum
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1157
  			return 1;
47d1a6e1e   wdenk   Initial revision
1158
  		}
712fbcf38   Stephen Warren   checkpatch whites...
1159
  		image_print_contents(hdr);
47d1a6e1e   wdenk   Initial revision
1160

712fbcf38   Stephen Warren   checkpatch whites...
1161
1162
1163
1164
  		puts("   Verifying Checksum ... ");
  		if (!image_check_dcrc(hdr)) {
  			puts("   Bad Data CRC
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1165
  			return 1;
47d1a6e1e   wdenk   Initial revision
1166
  		}
712fbcf38   Stephen Warren   checkpatch whites...
1167
1168
  		puts("OK
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1169
1170
1171
  		return 0;
  #if defined(CONFIG_FIT)
  	case IMAGE_FORMAT_FIT:
712fbcf38   Stephen Warren   checkpatch whites...
1172
1173
  		puts("   FIT image found
  ");
47d1a6e1e   wdenk   Initial revision
1174

712fbcf38   Stephen Warren   checkpatch whites...
1175
1176
1177
  		if (!fit_check_format(hdr)) {
  			puts("Bad FIT image format!
  ");
e32fea6ad   Marian Balakowicz   [new uImage] Add ...
1178
  			return 1;
47d1a6e1e   wdenk   Initial revision
1179
  		}
712fbcf38   Stephen Warren   checkpatch whites...
1180
  		fit_print_contents(hdr);
a4f243452   Bartlomiej Sieka   FIT: make iminfo ...
1181

b8da83665   Simon Glass   image: Rename fit...
1182
  		if (!fit_all_image_verify(hdr)) {
712fbcf38   Stephen Warren   checkpatch whites...
1183
1184
  			puts("Bad hash in FIT image!
  ");
a4f243452   Bartlomiej Sieka   FIT: make iminfo ...
1185
1186
  			return 1;
  		}
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1187
1188
1189
  		return 0;
  #endif
  	default:
712fbcf38   Stephen Warren   checkpatch whites...
1190
1191
  		puts("Unknown image format!
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1192
  		break;
47d1a6e1e   wdenk   Initial revision
1193
  	}
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1194
  	return 1;
47d1a6e1e   wdenk   Initial revision
1195
  }
0d4983930   wdenk   Patch by Kenneth ...
1196
1197
  
  U_BOOT_CMD(
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
1198
  	iminfo,	CONFIG_SYS_MAXARGS,	1,	do_iminfo,
2fb2604d5   Peter Tyser   Command usage cle...
1199
  	"print header information for application image",
8bde7f776   wdenk   * Code cleanup:
1200
1201
1202
1203
1204
1205
  	"addr [addr ...]
  "
  	"    - print header information for application image starting at
  "
  	"      address 'addr' in memory; this includes verification of the
  "
a89c33db9   Wolfgang Denk   General help mess...
1206
  	"      image contents (magic number, header and payload checksums)"
8bde7f776   wdenk   * Code cleanup:
1207
  );
25c751e9a   Matthew McClintock   * Support for FDT...
1208
  #endif
87a449c8a   Matthew McClintock   Support for FDT i...
1209

25c751e9a   Matthew McClintock   * Support for FDT...
1210

1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1211
1212
1213
  /*******************************************************************/
  /* imls - list all images found in flash */
  /*******************************************************************/
baa26db41   Jon Loeliger   common/cmd_[af]*:...
1214
  #if defined(CONFIG_CMD_IMLS)
8fdf1e0f6   Vipin Kumar   imls: Add support...
1215
  static int do_imls_nor(void)
27b207fd0   wdenk   * Implement new m...
1216
1217
1218
  {
  	flash_info_t *info;
  	int i, j;
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1219
  	void *hdr;
25c751e9a   Matthew McClintock   * Support for FDT...
1220

1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1221
  	for (i = 0, info = &flash_info[0];
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
1222
  		i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
25c751e9a   Matthew McClintock   * Support for FDT...
1223

27b207fd0   wdenk   * Implement new m...
1224
1225
  		if (info->flash_id == FLASH_UNKNOWN)
  			goto next_bank;
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1226
  		for (j = 0; j < info->sector_count; ++j) {
25c751e9a   Matthew McClintock   * Support for FDT...
1227

d5934ad77   Marian Balakowicz   [new uImage] Add ...
1228
1229
  			hdr = (void *)info->start[j];
  			if (!hdr)
b97a2a0a2   Marian Balakowicz   [new uImage] Defi...
1230
  				goto next_sector;
27b207fd0   wdenk   * Implement new m...
1231

712fbcf38   Stephen Warren   checkpatch whites...
1232
  			switch (genimg_get_format(hdr)) {
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1233
  			case IMAGE_FORMAT_LEGACY:
712fbcf38   Stephen Warren   checkpatch whites...
1234
  				if (!image_check_hcrc(hdr))
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1235
  					goto next_sector;
712fbcf38   Stephen Warren   checkpatch whites...
1236
1237
1238
  				printf("Legacy Image at %08lX:
  ", (ulong)hdr);
  				image_print_contents(hdr);
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1239

712fbcf38   Stephen Warren   checkpatch whites...
1240
1241
1242
1243
  				puts("   Verifying Checksum ... ");
  				if (!image_check_dcrc(hdr)) {
  					puts("Bad Data CRC
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1244
  				} else {
712fbcf38   Stephen Warren   checkpatch whites...
1245
1246
  					puts("OK
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1247
1248
1249
1250
  				}
  				break;
  #if defined(CONFIG_FIT)
  			case IMAGE_FORMAT_FIT:
712fbcf38   Stephen Warren   checkpatch whites...
1251
  				if (!fit_check_format(hdr))
e32fea6ad   Marian Balakowicz   [new uImage] Add ...
1252
  					goto next_sector;
712fbcf38   Stephen Warren   checkpatch whites...
1253
1254
1255
  				printf("FIT Image at %08lX:
  ", (ulong)hdr);
  				fit_print_contents(hdr);
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1256
  				break;
213bf8c82   Gerald Van Baren   Add a flattened d...
1257
  #endif
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1258
  			default:
27b207fd0   wdenk   * Implement new m...
1259
  				goto next_sector;
25c751e9a   Matthew McClintock   * Support for FDT...
1260
  			}
87a449c8a   Matthew McClintock   Support for FDT i...
1261

bdccc4fed   wdenk   * Map ISP1362 USB...
1262
  next_sector:		;
c76f951a7   Kumar Gala   Added support for...
1263
  		}
bdccc4fed   wdenk   * Map ISP1362 USB...
1264
  next_bank:	;
27b207fd0   wdenk   * Implement new m...
1265
  	}
8fdf1e0f6   Vipin Kumar   imls: Add support...
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
  	return 0;
  }
  #endif
  
  #if defined(CONFIG_CMD_IMLS_NAND)
  static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
  		size_t len)
  {
  	void *imgdata;
  	int ret;
  
  	imgdata = malloc(len);
  	if (!imgdata) {
  		printf("May be a Legacy Image at NAND device %d offset %08llX:
  ",
  				nand_dev, off);
  		printf("   Low memory(cannot allocate memory for image)
  ");
  		return -ENOMEM;
  	}
  
  	ret = nand_read_skip_bad(nand, off, &len,
  			imgdata);
  	if (ret < 0 && ret != -EUCLEAN) {
  		free(imgdata);
  		return ret;
  	}
  
  	if (!image_check_hcrc(imgdata)) {
  		free(imgdata);
  		return 0;
  	}
  
  	printf("Legacy Image at NAND device %d offset %08llX:
  ",
  			nand_dev, off);
  	image_print_contents(imgdata);
  
  	puts("   Verifying Checksum ... ");
  	if (!image_check_dcrc(imgdata))
  		puts("Bad Data CRC
  ");
  	else
  		puts("OK
  ");
  
  	free(imgdata);
  
  	return 0;
  }
  
  static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
  		size_t len)
  {
  	void *imgdata;
  	int ret;
  
  	imgdata = malloc(len);
  	if (!imgdata) {
  		printf("May be a FIT Image at NAND device %d offset %08llX:
  ",
  				nand_dev, off);
  		printf("   Low memory(cannot allocate memory for image)
  ");
  		return -ENOMEM;
  	}
  
  	ret = nand_read_skip_bad(nand, off, &len,
  			imgdata);
  	if (ret < 0 && ret != -EUCLEAN) {
  		free(imgdata);
  		return ret;
  	}
  
  	if (!fit_check_format(imgdata)) {
  		free(imgdata);
  		return 0;
  	}
  
  	printf("FIT Image at NAND device %d offset %08llX:
  ", nand_dev, off);
  
  	fit_print_contents(imgdata);
  	free(imgdata);
  
  	return 0;
  }
  
  static int do_imls_nand(void)
  {
  	nand_info_t *nand;
  	int nand_dev = nand_curr_device;
  	size_t len;
  	loff_t off;
  	u32 buffer[16];
  
  	if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
  		puts("
  No NAND devices available
  ");
  		return -ENODEV;
  	}
  
  	printf("
  ");
  
  	for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
  		nand = &nand_info[nand_dev];
  		if (!nand->name || !nand->size)
  			continue;
  
  		for (off = 0; off < nand->size; off += nand->erasesize) {
  			const image_header_t *header;
  			int ret;
  
  			if (nand_block_isbad(nand, off))
  				continue;
  
  			len = sizeof(buffer);
  
  			ret = nand_read(nand, off, &len, (u8 *)buffer);
  			if (ret < 0 && ret != -EUCLEAN) {
  				printf("NAND read error %d at offset %08llX
  ",
  						ret, off);
  				continue;
  			}
  
  			switch (genimg_get_format(buffer)) {
  			case IMAGE_FORMAT_LEGACY:
  				header = (const image_header_t *)buffer;
  
  				len = image_get_image_size(header);
  				nand_imls_legacyimage(nand, nand_dev, off, len);
  				break;
  #if defined(CONFIG_FIT)
  			case IMAGE_FORMAT_FIT:
  				len = fit_get_size(buffer);
  				nand_imls_fitimage(nand, nand_dev, off, len);
  				break;
  #endif
  			}
  		}
  	}
  
  	return 0;
  }
  #endif
  
  #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
  static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  {
  	int ret_nor = 0, ret_nand = 0;
  
  #if defined(CONFIG_CMD_IMLS)
  	ret_nor = do_imls_nor();
  #endif
  
  #if defined(CONFIG_CMD_IMLS_NAND)
  	ret_nand = do_imls_nand();
  #endif
  
  	if (ret_nor)
  		return ret_nor;
  
  	if (ret_nand)
  		return ret_nand;
c76f951a7   Kumar Gala   Added support for...
1433

27b207fd0   wdenk   * Implement new m...
1434
1435
  	return (0);
  }
c76f951a7   Kumar Gala   Added support for...
1436

27b207fd0   wdenk   * Implement new m...
1437
1438
  U_BOOT_CMD(
  	imls,	1,		1,	do_imls,
2fb2604d5   Peter Tyser   Command usage cle...
1439
  	"list all images found in flash",
27b207fd0   wdenk   * Implement new m...
1440
1441
  	"
  "
8fdf1e0f6   Vipin Kumar   imls: Add support...
1442
1443
1444
  	"    - Prints information about all images found at sector/block
  "
  	"      boundaries in nor/nand flash."
27b207fd0   wdenk   * Implement new m...
1445
  );
98a9c4d46   Matthew McClintock   * Modify bootm co...
1446
  #endif
47d1a6e1e   wdenk   Initial revision
1447

1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1448
  /*******************************************************************/
5cf746c30   Marian Balakowicz   [new uImage] Move...
1449
  /* helper routines */
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1450
  /*******************************************************************/
be2e5a09e   Joe Hershberger   Allow u-boot to b...
1451
  #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
a558ad711   Doug Anderson   bootm: Avoid 256-...
1452
1453
1454
  
  #define CONSOLE_ARG     "console="
  #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
3a8653b3a   Doug Anderson   cosmetic: Fixup f...
1455
  static void fixup_silent_linux(void)
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1456
  {
a558ad711   Doug Anderson   bootm: Avoid 256-...
1457
1458
  	char *buf;
  	const char *env_val;
3a8653b3a   Doug Anderson   cosmetic: Fixup f...
1459
  	char *cmdline = getenv("bootargs");
8d51aacd8   Simon Glass   RFC: bootm: Add s...
1460
  	int want_silent;
47d1a6e1e   wdenk   Initial revision
1461

8d51aacd8   Simon Glass   RFC: bootm: Add s...
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
  	/*
  	 * Only fix cmdline when requested. The environment variable can be:
  	 *
  	 *	no - we never fixup
  	 *	yes - we always fixup
  	 *	unset - we rely on the console silent flag
  	 */
  	want_silent = getenv_yesno("silent_linux");
  	if (want_silent == 0)
  		return;
  	else if (want_silent == -1 && !(gd->flags & GD_FLG_SILENT))
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1473
  		return;
47d1a6e1e   wdenk   Initial revision
1474

3a8653b3a   Doug Anderson   cosmetic: Fixup f...
1475
1476
  	debug("before silent fix-up: %s
  ", cmdline);
a558ad711   Doug Anderson   bootm: Avoid 256-...
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
  	if (cmdline && (cmdline[0] != '\0')) {
  		char *start = strstr(cmdline, CONSOLE_ARG);
  
  		/* Allocate space for maximum possible new command line */
  		buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1);
  		if (!buf) {
  			debug("%s: out of memory
  ", __func__);
  			return;
  		}
3a8653b3a   Doug Anderson   cosmetic: Fixup f...
1487
  		if (start) {
a558ad711   Doug Anderson   bootm: Avoid 256-...
1488
1489
1490
1491
  			char *end = strchr(start, ' ');
  			int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN;
  
  			strncpy(buf, cmdline, num_start_bytes);
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1492
  			if (end)
a558ad711   Doug Anderson   bootm: Avoid 256-...
1493
  				strcpy(buf + num_start_bytes, end);
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1494
  			else
a558ad711   Doug Anderson   bootm: Avoid 256-...
1495
  				buf[num_start_bytes] = '\0';
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1496
  		} else {
a558ad711   Doug Anderson   bootm: Avoid 256-...
1497
  			sprintf(buf, "%s %s", cmdline, CONSOLE_ARG);
47d1a6e1e   wdenk   Initial revision
1498
  		}
a558ad711   Doug Anderson   bootm: Avoid 256-...
1499
  		env_val = buf;
47d1a6e1e   wdenk   Initial revision
1500
  	} else {
a558ad711   Doug Anderson   bootm: Avoid 256-...
1501
1502
  		buf = NULL;
  		env_val = CONSOLE_ARG;
e79021223   Grant Likely   bootm/fdt: Only p...
1503
  	}
10aaf716c   Andy Fleming   Fix of_data copyi...
1504

a558ad711   Doug Anderson   bootm: Avoid 256-...
1505
1506
1507
1508
  	setenv("bootargs", env_val);
  	debug("after silent fix-up: %s
  ", env_val);
  	free(buf);
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1509
1510
  }
  #endif /* CONFIG_SILENT_CONSOLE */
38eb508e8   Gerald Van Baren   Reorganize and fi...
1511

eeaef5e43   Steven Stallion   cmd_bootm: Add co...
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
  #if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9)
  static void copy_args(char *dest, int argc, char * const argv[], char delim)
  {
  	int i;
  
  	for (i = 0; i < argc; i++) {
  		if (i > 0)
  			*dest++ = delim;
  		strcpy(dest, argv[i]);
  		dest += strlen(argv[i]);
  	}
  }
  #endif
38eb508e8   Gerald Van Baren   Reorganize and fi...
1525

1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1526
1527
1528
  /*******************************************************************/
  /* OS booting routines */
  /*******************************************************************/
c76f951a7   Kumar Gala   Added support for...
1529

b1d0db180   Kumar Gala   bootm: Added CONF...
1530
  #ifdef CONFIG_BOOTM_NETBSD
712fbcf38   Stephen Warren   checkpatch whites...
1531
  static int do_bootm_netbsd(int flag, int argc, char * const argv[],
8a5ea3e61   Marian Balakowicz   [new uImage] Move...
1532
  			    bootm_headers_t *images)
d791b1dc3   wdenk   * Make sure Block...
1533
  {
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1534
  	void (*loader)(bd_t *, image_header_t *, char *, char *);
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1535
  	image_header_t *os_hdr, *hdr;
f13e7b2e9   Marian Balakowicz   [new uImage] Clea...
1536
  	ulong kernel_data, kernel_len;
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1537
1538
  	char *consdev;
  	char *cmdline;
5b629319c   Miao Yan   common/cmd_bootm....
1539
  	if (flag != BOOTM_STATE_OS_GO)
7af26b166   Simon Glass   blackfin: x86: bo...
1540
  		return 0;
49c3a861d   Kumar Gala   bootm: Add subcom...
1541

d5934ad77   Marian Balakowicz   [new uImage] Add ...
1542
1543
  #if defined(CONFIG_FIT)
  	if (!images->legacy_hdr_valid) {
712fbcf38   Stephen Warren   checkpatch whites...
1544
  		fit_unsupported_reset("NetBSD");
40d7e99d3   Kumar Gala   bootm: refactor d...
1545
  		return 1;
38eb508e8   Gerald Van Baren   Reorganize and fi...
1546
1547
  	}
  #endif
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1548
  	hdr = images->legacy_hdr_os;
47d1a6e1e   wdenk   Initial revision
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
  
  	/*
  	 * Booting a (NetBSD) kernel image
  	 *
  	 * This process is pretty similar to a standalone application:
  	 * The (first part of an multi-) image must be a stage-2 loader,
  	 * which in turn is responsible for loading & invoking the actual
  	 * kernel.  The only differences are the parameters being passed:
  	 * besides the board info strucure, the loader expects a command
  	 * line, the name of the console device, and (optionally) the
  	 * address of the original image header.
  	 */
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1561
  	os_hdr = NULL;
712fbcf38   Stephen Warren   checkpatch whites...
1562
1563
  	if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
  		image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
f13e7b2e9   Marian Balakowicz   [new uImage] Clea...
1564
  		if (kernel_len)
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1565
  			os_hdr = hdr;
f13e7b2e9   Marian Balakowicz   [new uImage] Clea...
1566
  	}
47d1a6e1e   wdenk   Initial revision
1567
1568
  
  	consdev = "";
712fbcf38   Stephen Warren   checkpatch whites...
1569
  #if   defined(CONFIG_8xx_CONS_SMC1)
47d1a6e1e   wdenk   Initial revision
1570
  	consdev = "smc1";
712fbcf38   Stephen Warren   checkpatch whites...
1571
  #elif defined(CONFIG_8xx_CONS_SMC2)
47d1a6e1e   wdenk   Initial revision
1572
  	consdev = "smc2";
712fbcf38   Stephen Warren   checkpatch whites...
1573
  #elif defined(CONFIG_8xx_CONS_SCC2)
47d1a6e1e   wdenk   Initial revision
1574
  	consdev = "scc2";
712fbcf38   Stephen Warren   checkpatch whites...
1575
  #elif defined(CONFIG_8xx_CONS_SCC3)
47d1a6e1e   wdenk   Initial revision
1576
1577
  	consdev = "scc3";
  #endif
983c72f47   Simon Glass   Clarify bootm OS ...
1578
  	if (argc > 0) {
47d1a6e1e   wdenk   Initial revision
1579
1580
  		ulong len;
  		int   i;
983c72f47   Simon Glass   Clarify bootm OS ...
1581
  		for (i = 0, len = 0; i < argc; i += 1)
712fbcf38   Stephen Warren   checkpatch whites...
1582
1583
  			len += strlen(argv[i]) + 1;
  		cmdline = malloc(len);
eeaef5e43   Steven Stallion   cmd_bootm: Add co...
1584
  		copy_args(cmdline, argc, argv, ' ');
712fbcf38   Stephen Warren   checkpatch whites...
1585
  	} else if ((cmdline = getenv("bootargs")) == NULL) {
47d1a6e1e   wdenk   Initial revision
1586
1587
  		cmdline = "";
  	}
c160a9544   Kumar Gala   bootm: refactor e...
1588
  	loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
47d1a6e1e   wdenk   Initial revision
1589

712fbcf38   Stephen Warren   checkpatch whites...
1590
1591
1592
  	printf("## Transferring control to NetBSD stage-2 loader "
  		"(at address %08lx) ...
  ",
47d1a6e1e   wdenk   Initial revision
1593
  		(ulong)loader);
770605e4f   Simon Glass   bootstage: Replac...
1594
  	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
47d1a6e1e   wdenk   Initial revision
1595
1596
1597
  
  	/*
  	 * NetBSD Stage-2 Loader Parameters:
e2ce81696   Kees Jongenburger   netbsd:fix docume...
1598
1599
1600
1601
  	 *   arg[0]: pointer to board info data
  	 *   arg[1]: image load address
  	 *   arg[2]: char pointer to the console device to use
  	 *   arg[3]: char pointer to the boot arguments
47d1a6e1e   wdenk   Initial revision
1602
  	 */
712fbcf38   Stephen Warren   checkpatch whites...
1603
  	(*loader)(gd->bd, os_hdr, consdev, cmdline);
40d7e99d3   Kumar Gala   bootm: refactor d...
1604
1605
  
  	return 1;
47d1a6e1e   wdenk   Initial revision
1606
  }
b1d0db180   Kumar Gala   bootm: Added CONF...
1607
  #endif /* CONFIG_BOOTM_NETBSD*/
47d1a6e1e   wdenk   Initial revision
1608

1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1609
  #ifdef CONFIG_LYNXKDI
712fbcf38   Stephen Warren   checkpatch whites...
1610
  static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
8a5ea3e61   Marian Balakowicz   [new uImage] Move...
1611
  			     bootm_headers_t *images)
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1612
  {
cb1c48969   Marian Balakowicz   Restore the abili...
1613
  	image_header_t *hdr = &images->legacy_hdr_os_copy;
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1614

5b629319c   Miao Yan   common/cmd_bootm....
1615
  	if (flag != BOOTM_STATE_OS_GO)
7af26b166   Simon Glass   blackfin: x86: bo...
1616
  		return 0;
49c3a861d   Kumar Gala   bootm: Add subcom...
1617

d5934ad77   Marian Balakowicz   [new uImage] Add ...
1618
1619
  #if defined(CONFIG_FIT)
  	if (!images->legacy_hdr_valid) {
712fbcf38   Stephen Warren   checkpatch whites...
1620
  		fit_unsupported_reset("Lynx");
40d7e99d3   Kumar Gala   bootm: refactor d...
1621
  		return 1;
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1622
1623
  	}
  #endif
712fbcf38   Stephen Warren   checkpatch whites...
1624
  	lynxkdi_boot((image_header_t *)hdr);
40d7e99d3   Kumar Gala   bootm: refactor d...
1625
1626
  
  	return 1;
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1627
1628
  }
  #endif /* CONFIG_LYNXKDI */
b1d0db180   Kumar Gala   bootm: Added CONF...
1629
  #ifdef CONFIG_BOOTM_RTEMS
712fbcf38   Stephen Warren   checkpatch whites...
1630
  static int do_bootm_rtems(int flag, int argc, char * const argv[],
8a5ea3e61   Marian Balakowicz   [new uImage] Move...
1631
  			   bootm_headers_t *images)
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1632
  {
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1633
  	void (*entry_point)(bd_t *);
d791b1dc3   wdenk   * Make sure Block...
1634

5b629319c   Miao Yan   common/cmd_bootm....
1635
  	if (flag != BOOTM_STATE_OS_GO)
7af26b166   Simon Glass   blackfin: x86: bo...
1636
  		return 0;
49c3a861d   Kumar Gala   bootm: Add subcom...
1637

d5934ad77   Marian Balakowicz   [new uImage] Add ...
1638
1639
  #if defined(CONFIG_FIT)
  	if (!images->legacy_hdr_valid) {
712fbcf38   Stephen Warren   checkpatch whites...
1640
  		fit_unsupported_reset("RTEMS");
40d7e99d3   Kumar Gala   bootm: refactor d...
1641
  		return 1;
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1642
1643
  	}
  #endif
c160a9544   Kumar Gala   bootm: refactor e...
1644
  	entry_point = (void (*)(bd_t *))images->ep;
d791b1dc3   wdenk   * Make sure Block...
1645

712fbcf38   Stephen Warren   checkpatch whites...
1646
1647
  	printf("## Transferring control to RTEMS (at address %08lx) ...
  ",
d791b1dc3   wdenk   * Make sure Block...
1648
  		(ulong)entry_point);
770605e4f   Simon Glass   bootstage: Replac...
1649
  	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
d791b1dc3   wdenk   * Make sure Block...
1650
1651
1652
1653
1654
  
  	/*
  	 * RTEMS Parameters:
  	 *   r3: ptr to board info data
  	 */
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
1655
  	(*entry_point)(gd->bd);
40d7e99d3   Kumar Gala   bootm: refactor d...
1656
1657
  
  	return 1;
d791b1dc3   wdenk   * Make sure Block...
1658
  }
b1d0db180   Kumar Gala   bootm: Added CONF...
1659
  #endif /* CONFIG_BOOTM_RTEMS */
7f70e8530   wdenk   * Patch by David ...
1660

3df619579   Torkel Lundgren   Add support for o...
1661
  #if defined(CONFIG_BOOTM_OSE)
712fbcf38   Stephen Warren   checkpatch whites...
1662
  static int do_bootm_ose(int flag, int argc, char * const argv[],
3df619579   Torkel Lundgren   Add support for o...
1663
1664
1665
  			   bootm_headers_t *images)
  {
  	void (*entry_point)(void);
5b629319c   Miao Yan   common/cmd_bootm....
1666
  	if (flag != BOOTM_STATE_OS_GO)
7af26b166   Simon Glass   blackfin: x86: bo...
1667
  		return 0;
3df619579   Torkel Lundgren   Add support for o...
1668
1669
1670
  
  #if defined(CONFIG_FIT)
  	if (!images->legacy_hdr_valid) {
712fbcf38   Stephen Warren   checkpatch whites...
1671
  		fit_unsupported_reset("OSE");
3df619579   Torkel Lundgren   Add support for o...
1672
1673
1674
1675
1676
  		return 1;
  	}
  #endif
  
  	entry_point = (void (*)(void))images->ep;
712fbcf38   Stephen Warren   checkpatch whites...
1677
1678
  	printf("## Transferring control to OSE (at address %08lx) ...
  ",
3df619579   Torkel Lundgren   Add support for o...
1679
  		(ulong)entry_point);
770605e4f   Simon Glass   bootstage: Replac...
1680
  	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
3df619579   Torkel Lundgren   Add support for o...
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
  
  	/*
  	 * OSE Parameters:
  	 *   None
  	 */
  	(*entry_point)();
  
  	return 1;
  }
  #endif /* CONFIG_BOOTM_OSE */
04d414090   Steven Stallion   image: Add suppor...
1691
1692
1693
1694
1695
  #if defined(CONFIG_BOOTM_PLAN9)
  static int do_bootm_plan9(int flag, int argc, char * const argv[],
  			   bootm_headers_t *images)
  {
  	void (*entry_point)(void);
eeaef5e43   Steven Stallion   cmd_bootm: Add co...
1696
  	char *s;
04d414090   Steven Stallion   image: Add suppor...
1697

5b629319c   Miao Yan   common/cmd_bootm....
1698
  	if (flag != BOOTM_STATE_OS_GO)
7af26b166   Simon Glass   blackfin: x86: bo...
1699
  		return 0;
04d414090   Steven Stallion   image: Add suppor...
1700
1701
1702
1703
1704
1705
1706
  
  #if defined(CONFIG_FIT)
  	if (!images->legacy_hdr_valid) {
  		fit_unsupported_reset("Plan 9");
  		return 1;
  	}
  #endif
eeaef5e43   Steven Stallion   cmd_bootm: Add co...
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
  	/* See README.plan9 */
  	s = getenv("confaddr");
  	if (s != NULL) {
  		char *confaddr = (char *)simple_strtoul(s, NULL, 16);
  
  		if (argc > 0) {
  			copy_args(confaddr, argc, argv, '
  ');
  		} else {
  			s = getenv("bootargs");
  			if (s != NULL)
  				strcpy(confaddr, s);
  		}
  	}
04d414090   Steven Stallion   image: Add suppor...
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
  	entry_point = (void (*)(void))images->ep;
  
  	printf("## Transferring control to Plan 9 (at address %08lx) ...
  ",
  		(ulong)entry_point);
  
  	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  
  	/*
  	 * Plan 9 Parameters:
  	 *   None
  	 */
  	(*entry_point)();
  
  	return 1;
  }
  #endif /* CONFIG_BOOTM_PLAN9 */
871a57bb8   Miao Yan   common/cmd_bootm:...
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
  #if defined(CONFIG_BOOTM_VXWORKS) && \
  	(defined(CONFIG_PPC) || defined(CONFIG_ARM))
  
  void do_bootvx_fdt(bootm_headers_t *images)
  {
  #if defined(CONFIG_OF_LIBFDT)
  	int ret;
  	char *bootline;
  	ulong of_size = images->ft_len;
  	char **of_flat_tree = &images->ft_addr;
  	struct lmb *lmb = &images->lmb;
  
  	if (*of_flat_tree) {
  		boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);
  
  		ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size);
  		if (ret)
  			return;
  
  		ret = fdt_add_subnode(*of_flat_tree, 0, "chosen");
  		if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) {
  			bootline = getenv("bootargs");
  			if (bootline) {
  				ret = fdt_find_and_setprop(*of_flat_tree,
  						"/chosen", "bootargs",
  						bootline,
  						strlen(bootline) + 1, 1);
  				if (ret < 0) {
  					printf("## ERROR: %s : %s
  ", __func__,
  					       fdt_strerror(ret));
  					return;
  				}
  			}
  		} else {
  			printf("## ERROR: %s : %s
  ", __func__,
  			       fdt_strerror(ret));
  			return;
  		}
  	}
  #endif
  
  	boot_prep_vxworks(images);
  
  	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
  
  #if defined(CONFIG_OF_LIBFDT)
  	printf("## Starting vxWorks at 0x%08lx, device tree at 0x%08lx ...
  ",
  	       (ulong)images->ep, (ulong)*of_flat_tree);
  #else
  	printf("## Starting vxWorks at 0x%08lx
  ", (ulong)images->ep);
  #endif
  
  	boot_jump_vxworks(images);
  
  	puts("## vxWorks terminated
  ");
  }
712fbcf38   Stephen Warren   checkpatch whites...
1799
  static int do_bootm_vxworks(int flag, int argc, char * const argv[],
8a5ea3e61   Marian Balakowicz   [new uImage] Move...
1800
  			     bootm_headers_t *images)
47d1a6e1e   wdenk   Initial revision
1801
  {
5b629319c   Miao Yan   common/cmd_bootm....
1802
  	if (flag != BOOTM_STATE_OS_GO)
7af26b166   Simon Glass   blackfin: x86: bo...
1803
  		return 0;
49c3a861d   Kumar Gala   bootm: Add subcom...
1804

d5934ad77   Marian Balakowicz   [new uImage] Add ...
1805
  #if defined(CONFIG_FIT)
cb1c48969   Marian Balakowicz   Restore the abili...
1806
  	if (!images->legacy_hdr_valid) {
712fbcf38   Stephen Warren   checkpatch whites...
1807
  		fit_unsupported_reset("VxWorks");
40d7e99d3   Kumar Gala   bootm: refactor d...
1808
  		return 1;
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1809
1810
  	}
  #endif
47d1a6e1e   wdenk   Initial revision
1811

871a57bb8   Miao Yan   common/cmd_bootm:...
1812
  	do_bootvx_fdt(images);
40d7e99d3   Kumar Gala   bootm: refactor d...
1813
1814
  
  	return 1;
47d1a6e1e   wdenk   Initial revision
1815
  }
17ab52fef   Miao Yan   common/cmd_bootm....
1816
  #endif
47d1a6e1e   wdenk   Initial revision
1817

17ab52fef   Miao Yan   common/cmd_bootm....
1818
  #if defined(CONFIG_CMD_ELF)
54841ab50   Wolfgang Denk   Make sure that ar...
1819
  static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
8a5ea3e61   Marian Balakowicz   [new uImage] Move...
1820
  			    bootm_headers_t *images)
47d1a6e1e   wdenk   Initial revision
1821
  {
47d1a6e1e   wdenk   Initial revision
1822
1823
  	char *local_args[2];
  	char str[16];
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1824

5b629319c   Miao Yan   common/cmd_bootm....
1825
  	if (flag != BOOTM_STATE_OS_GO)
7af26b166   Simon Glass   blackfin: x86: bo...
1826
  		return 0;
49c3a861d   Kumar Gala   bootm: Add subcom...
1827

d5934ad77   Marian Balakowicz   [new uImage] Add ...
1828
1829
  #if defined(CONFIG_FIT)
  	if (!images->legacy_hdr_valid) {
712fbcf38   Stephen Warren   checkpatch whites...
1830
  		fit_unsupported_reset("QNX");
40d7e99d3   Kumar Gala   bootm: refactor d...
1831
  		return 1;
d5934ad77   Marian Balakowicz   [new uImage] Add ...
1832
1833
  	}
  #endif
47d1a6e1e   wdenk   Initial revision
1834

c160a9544   Kumar Gala   bootm: refactor e...
1835
  	sprintf(str, "%lx", images->ep); /* write entry-point into string */
47d1a6e1e   wdenk   Initial revision
1836
1837
  	local_args[0] = argv[0];
  	local_args[1] = str;	/* and provide it via the arguments */
40d7e99d3   Kumar Gala   bootm: refactor d...
1838
1839
1840
  	do_bootelf(NULL, 0, 2, local_args);
  
  	return 1;
47d1a6e1e   wdenk   Initial revision
1841
  }
902531788   Jon Loeliger   common/: Remove l...
1842
  #endif
f5ed9e390   Peter Tyser   Add support for b...
1843
1844
  
  #ifdef CONFIG_INTEGRITY
712fbcf38   Stephen Warren   checkpatch whites...
1845
  static int do_bootm_integrity(int flag, int argc, char * const argv[],
f5ed9e390   Peter Tyser   Add support for b...
1846
1847
1848
  			   bootm_headers_t *images)
  {
  	void (*entry_point)(void);
5b629319c   Miao Yan   common/cmd_bootm....
1849
  	if (flag != BOOTM_STATE_OS_GO)
7af26b166   Simon Glass   blackfin: x86: bo...
1850
  		return 0;
49c3a861d   Kumar Gala   bootm: Add subcom...
1851

f5ed9e390   Peter Tyser   Add support for b...
1852
1853
  #if defined(CONFIG_FIT)
  	if (!images->legacy_hdr_valid) {
712fbcf38   Stephen Warren   checkpatch whites...
1854
  		fit_unsupported_reset("INTEGRITY");
f5ed9e390   Peter Tyser   Add support for b...
1855
1856
1857
1858
1859
  		return 1;
  	}
  #endif
  
  	entry_point = (void (*)(void))images->ep;
712fbcf38   Stephen Warren   checkpatch whites...
1860
1861
  	printf("## Transferring control to INTEGRITY (at address %08lx) ...
  ",
f5ed9e390   Peter Tyser   Add support for b...
1862
  		(ulong)entry_point);
770605e4f   Simon Glass   bootstage: Replac...
1863
  	bootstage_mark(BOOTSTAGE_ID_RUN_OS);
f5ed9e390   Peter Tyser   Add support for b...
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
  
  	/*
  	 * INTEGRITY Parameters:
  	 *   None
  	 */
  	(*entry_point)();
  
  	return 1;
  }
  #endif
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1874
1875
  
  #ifdef CONFIG_CMD_BOOTZ
a5266d6b5   Simon Glass   bootm: Clean up b...
1876
  int __weak bootz_setup(ulong image, ulong *start, ulong *end)
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1877
1878
1879
1880
1881
1882
1883
  {
  	/* Please define bootz_setup() for your platform */
  
  	puts("Your platform's zImage format isn't supported yet!
  ");
  	return -1;
  }
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1884
1885
1886
1887
1888
1889
1890
1891
  
  /*
   * zImage booting support
   */
  static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
  			char * const argv[], bootm_headers_t *images)
  {
  	int ret;
a5266d6b5   Simon Glass   bootm: Clean up b...
1892
  	ulong zi_start, zi_end;
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1893

35fc84fa1   Simon Glass   Refactor the boot...
1894
1895
  	ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
  			      images, 1);
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1896
1897
  
  	/* Setup Linux kernel zImage entry point */
2b9599e01   Tom Rini   cmd_bootm.c: Make...
1898
  	if (!argc) {
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1899
1900
1901
1902
1903
  		images->ep = load_addr;
  		debug("*  kernel: default image load address = 0x%08lx
  ",
  				load_addr);
  	} else {
2b9599e01   Tom Rini   cmd_bootm.c: Make...
1904
  		images->ep = simple_strtoul(argv[0], NULL, 16);
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1905
1906
1907
1908
  		debug("*  kernel: cmdline image address = 0x%08lx
  ",
  			images->ep);
  	}
a5266d6b5   Simon Glass   bootm: Clean up b...
1909
  	ret = bootz_setup(images->ep, &zi_start, &zi_end);
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1910
1911
1912
1913
  	if (ret != 0)
  		return 1;
  
  	lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
225fd8c5d   Tom Rini   cmd_bootm.c: Make...
1914
1915
1916
1917
  	/*
  	 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
  	 * have a header that provide this informaiton.
  	 */
2b9599e01   Tom Rini   cmd_bootm.c: Make...
1918
1919
  	if (bootm_find_ramdisk(flag, argc, argv))
  		return 1;
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1920

2b9599e01   Tom Rini   cmd_bootm.c: Make...
1921
1922
1923
1924
1925
1926
  #if defined(CONFIG_OF_LIBFDT)
  	if (bootm_find_fdt(flag, argc, argv))
  		return 1;
  #endif
  
  	return 0;
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1927
  }
da620222f   Rob Herring   bootz: un-statici...
1928
  int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1929
  {
35fc84fa1   Simon Glass   Refactor the boot...
1930
  	int ret;
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1931

2b9599e01   Tom Rini   cmd_bootm.c: Make...
1932
1933
  	/* Consume 'bootz' */
  	argc--; argv++;
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1934
1935
  	if (bootz_start(cmdtp, flag, argc, argv, &images))
  		return 1;
385501d38   Simon Glass   bootm: Disable in...
1936
1937
1938
1939
1940
  	/*
  	 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
  	 * disable interrupts ourselves
  	 */
  	bootm_disable_interrupts();
fb1b139bb   Simon Glass   bootm: Add the mi...
1941
  	images.os.os = IH_OS_LINUX;
35fc84fa1   Simon Glass   Refactor the boot...
1942
  	ret = do_bootm_states(cmdtp, flag, argc, argv,
fb1b139bb   Simon Glass   bootm: Add the mi...
1943
1944
  			      BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
  			      BOOTM_STATE_OS_GO,
d0ae31eb0   Simon Glass   Add a 'fake' go c...
1945
  			      &images, 1);
f8be7d659   Joe Hershberger   net: Improve the ...
1946

35fc84fa1   Simon Glass   Refactor the boot...
1947
  	return ret;
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1948
  }
088f1b199   Kim Phillips   common/cmd_*.c: s...
1949
1950
  #ifdef CONFIG_SYS_LONGHELP
  static char bootz_help_text[] =
017e1f3f9   Marek Vasut   BOOT: Add RAW ram...
1951
1952
1953
1954
  	"[addr [initrd[:size]] [fdt]]
  "
  	"    - boot Linux zImage stored in memory
  "
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1955
1956
  	"\tThe argument 'initrd' is optional and specifies the address
  "
017e1f3f9   Marek Vasut   BOOT: Add RAW ram...
1957
1958
1959
1960
  	"\tof the initrd in memory. The optional argument ':size' allows
  "
  	"\tspecifying the size of RAW initrd.
  "
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
  #if defined(CONFIG_OF_LIBFDT)
  	"\tWhen booting a Linux kernel which requires a flat device-tree
  "
  	"\ta third argument is required which is the address of the
  "
  	"\tdevice-tree blob. To boot that kernel without an initrd image,
  "
  	"\tuse a '-' for the second argument. If you do not pass a third
  "
  	"\ta bd_info struct will be passed instead
  "
  #endif
088f1b199   Kim Phillips   common/cmd_*.c: s...
1973
1974
1975
1976
1977
1978
  	"";
  #endif
  
  U_BOOT_CMD(
  	bootz,	CONFIG_SYS_MAXARGS,	1,	do_bootz,
  	"boot Linux zImage image from memory", bootz_help_text
44f074c77   Marek Vasut   BOOT: Add "bootz"...
1979
1980
  );
  #endif	/* CONFIG_CMD_BOOTZ */