Blame view

cmd/bootm.c 14.3 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
7
8
9
10
11
   */
  
  /*
   * Boot support
   */
  #include <common.h>
b63964037   Simon Glass   bootm: Split out ...
12
  #include <bootm.h>
47d1a6e1e   wdenk   Initial revision
13
  #include <command.h>
7f70e8530   wdenk   * Patch by David ...
14
  #include <environment.h>
90268b878   Simon Glass   x86: Support load...
15
  #include <errno.h>
b63964037   Simon Glass   bootm: Split out ...
16
  #include <image.h>
b63964037   Simon Glass   bootm: Split out ...
17
18
  #include <malloc.h>
  #include <nand.h>
47d1a6e1e   wdenk   Initial revision
19
  #include <asm/byteorder.h>
b63964037   Simon Glass   bootm: Split out ...
20
21
22
  #include <linux/ctype.h>
  #include <linux/err.h>
  #include <u-boot/zlib.h>
20dde48bc   Peter Korsgaard   add lzop decompre...
23

1ee1180b6   Marian Balakowicz   [new uImage] Clea...
24
  DECLARE_GLOBAL_DATA_PTR;
228f29ac6   wdenk   * Improve log buf...
25

baa26db41   Jon Loeliger   common/cmd_[af]*:...
26
  #if defined(CONFIG_CMD_IMI)
712fbcf38   Stephen Warren   checkpatch whites...
27
  static int image_info(unsigned long addr);
47d1a6e1e   wdenk   Initial revision
28
  #endif
27b207fd0   wdenk   * Implement new m...
29

baa26db41   Jon Loeliger   common/cmd_[af]*:...
30
  #if defined(CONFIG_CMD_IMLS)
27b207fd0   wdenk   * Implement new m...
31
  #include <flash.h>
ca5def3f3   Stefan Roese   cfi_flash: Simpli...
32
  #include <mtd/cfi_flash.h>
e6f2e9023   Marian Balakowicz   Added support for...
33
  extern flash_info_t flash_info[]; /* info for FLASH chips */
8fdf1e0f6   Vipin Kumar   imls: Add support...
34
35
36
  #endif
  
  #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
712fbcf38   Stephen Warren   checkpatch whites...
37
  static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
27b207fd0   wdenk   * Implement new m...
38
  #endif
49c3a861d   Kumar Gala   bootm: Add subcom...
39
40
  /* we overload the cmd field with our state machine info instead of a
   * function pointer */
f74d9bd2a   Frans Meulenbroeks   cmd_bootm.c: made...
41
  static cmd_tbl_t cmd_bootm_sub[] = {
49c3a861d   Kumar Gala   bootm: Add subcom...
42
43
  	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...
44
  #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
49c3a861d   Kumar Gala   bootm: Add subcom...
45
46
47
48
49
  	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...
50
  	U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
224c90d10   Peter Tyser   bootm: Fix help m...
51
  	U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
49c3a861d   Kumar Gala   bootm: Add subcom...
52
  	U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
d0ae31eb0   Simon Glass   Add a 'fake' go c...
53
  	U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""),
49c3a861d   Kumar Gala   bootm: Add subcom...
54
55
  	U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
  };
088f1b199   Kim Phillips   common/cmd_*.c: s...
56
  static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
712fbcf38   Stephen Warren   checkpatch whites...
57
  			char * const argv[])
49c3a861d   Kumar Gala   bootm: Add subcom...
58
59
  {
  	int ret = 0;
6d6f12363   Simon Glass   sandbox: Add boot...
60
  	long state;
49c3a861d   Kumar Gala   bootm: Add subcom...
61
  	cmd_tbl_t *c;
49c3a861d   Kumar Gala   bootm: Add subcom...
62

983c72f47   Simon Glass   Clarify bootm OS ...
63
64
  	c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
  	argc--; argv++;
49c3a861d   Kumar Gala   bootm: Add subcom...
65
66
  
  	if (c) {
6d6f12363   Simon Glass   sandbox: Add boot...
67
  		state = (long)c->cmd;
983c72f47   Simon Glass   Clarify bootm OS ...
68
  		if (state == BOOTM_STATE_START)
35fc84fa1   Simon Glass   Refactor the boot...
69
  			state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER;
47e26b1bf   Wolfgang Denk   cmd_usage(): simp...
70
71
  	} else {
  		/* Unrecognized command */
4c12eeb8b   Simon Glass   Convert cmd_usage...
72
  		return CMD_RET_USAGE;
49c3a861d   Kumar Gala   bootm: Add subcom...
73
  	}
ff6c032ea   Heiko Schocher   spl: fix calling ...
74
75
  	if (((state & BOOTM_STATE_START) != BOOTM_STATE_START) &&
  	    images.state >= state) {
712fbcf38   Stephen Warren   checkpatch whites...
76
77
  		printf("Trying to execute a command out of order
  ");
4c12eeb8b   Simon Glass   Convert cmd_usage...
78
  		return CMD_RET_USAGE;
49c3a861d   Kumar Gala   bootm: Add subcom...
79
  	}
35fc84fa1   Simon Glass   Refactor the boot...
80
  	ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0);
49c3a861d   Kumar Gala   bootm: Add subcom...
81
82
83
  
  	return ret;
  }
396f635b8   Kumar Gala   bootm: refactor i...
84
85
86
  /*******************************************************************/
  /* bootm - boot application image from image in memory */
  /*******************************************************************/
be0831593   Kumar Gala   bootm: Move to us...
87

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

be0831593   Kumar Gala   bootm: Move to us...
93
94
  	if (!relocated) {
  		int i;
58bd77db9   Daniel Schwierzeck   bootm: relocate n...
95

58bd77db9   Daniel Schwierzeck   bootm: relocate n...
96
97
98
  		/* 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...
99
100
  		relocated = 1;
  	}
521af04d8   Peter Tyser   Conditionally per...
101
  #endif
396f635b8   Kumar Gala   bootm: refactor i...
102

49c3a861d   Kumar Gala   bootm: Add subcom...
103
  	/* determine if we have a sub command */
983c72f47   Simon Glass   Clarify bootm OS ...
104
105
  	argc--; argv++;
  	if (argc > 0) {
49c3a861d   Kumar Gala   bootm: Add subcom...
106
  		char *endp;
983c72f47   Simon Glass   Clarify bootm OS ...
107
108
  		simple_strtoul(argv[0], &endp, 16);
  		/* endp pointing to NULL means that argv[0] was just a
49c3a861d   Kumar Gala   bootm: Add subcom...
109
110
111
112
113
114
115
116
117
118
  		 * 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);
  	}
98d4faefd   Ye Li   MLK-12500-1 HAB: ...
119
120
121
  #ifdef CONFIG_SECURE_BOOT
  	extern int authenticate_image(
  			uint32_t ddr_start, uint32_t raw_image_size);
3825c3fed   Ye Li   MLK-17086 bootm: ...
122
123
124
125
  #ifdef CONFIG_IMX_OPTEE
  	ulong tee_addr = 0;
  	int ret;
  	ulong zi_start, zi_end;
a7c0fbbf9   Ye Li   MLK-18588 bootm: ...
126
  	tee_addr = env_get_ulong("tee_addr", 16, tee_addr);
3825c3fed   Ye Li   MLK-17086 bootm: ...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  	if (!tee_addr) {
  		printf("Not valid tee_addr, Please check
  ");
  		return 1;
  	}
  
  	switch (genimg_get_format((const void *)tee_addr)) {
  	case IMAGE_FORMAT_LEGACY:
  		if (authenticate_image(tee_addr,
  		       image_get_image_size((image_header_t *)tee_addr)) != 0) {
  		       printf("Authenticate uImage Fail, Please check
  ");
  		       return 1;
  		}
  		break;
  	default:
  		printf("Not valid image format for Authentication, Please check
  ");
  		return 1;
  	};
  
  	ret = bootz_setup(load_addr, &zi_start, &zi_end);
  	if (ret != 0)
  		return 1;
  
  	if (authenticate_image(load_addr, zi_end - zi_start) != 0) {
  		printf("Authenticate zImage Fail, Please check
  ");
  		return 1;
  	}
  
  #else
98d4faefd   Ye Li   MLK-12500-1 HAB: ...
159
160
161
162
163
164
165
166
167
168
169
170
171
  	switch (genimg_get_format((const void *)load_addr)) {
  #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
  	case IMAGE_FORMAT_LEGACY:
  		if (authenticate_image(load_addr,
  			image_get_image_size((image_header_t *)load_addr)) != 0) {
  			printf("Authenticate uImage Fail, Please check
  ");
  			return 1;
  		}
  		break;
  #endif
  #ifdef CONFIG_ANDROID_BOOT_IMAGE
  	case IMAGE_FORMAT_ANDROID:
cce0bd746   Yu Shan   [iot] Check Trust...
172
173
  	default:
  		/* Android use AVB verify. Also here we cannot get IMAGE_FORMAT_ANDROID */
98d4faefd   Ye Li   MLK-12500-1 HAB: ...
174
  		break;
cce0bd746   Yu Shan   [iot] Check Trust...
175
  #else
98d4faefd   Ye Li   MLK-12500-1 HAB: ...
176
177
178
179
  	default:
  		printf("Not valid image format for Authentication, Please check
  ");
  		return 1;
cce0bd746   Yu Shan   [iot] Check Trust...
180
  #endif /* CONFIG_ANDROID_BOOT_IMAGE */
98d4faefd   Ye Li   MLK-12500-1 HAB: ...
181
182
  	}
  #endif
3825c3fed   Ye Li   MLK-17086 bootm: ...
183
  #endif
98d4faefd   Ye Li   MLK-12500-1 HAB: ...
184

35fc84fa1   Simon Glass   Refactor the boot...
185
186
  	return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START |
  		BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER |
3d187b392   Tom Rini   cmd_bootm.c: Only...
187
  		BOOTM_STATE_LOADOS |
c2e7e72bb   Rick Altherr   bootm: relocate r...
188
189
190
  #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
  		BOOTM_STATE_RAMDISK |
  #endif
3d187b392   Tom Rini   cmd_bootm.c: Only...
191
192
193
  #if defined(CONFIG_PPC) || defined(CONFIG_MIPS)
  		BOOTM_STATE_OS_CMDLINE |
  #endif
5c427e49c   Paul Burton   bootm: use BOOTM_...
194
195
  		BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
  		BOOTM_STATE_OS_GO, &images, 1);
47d1a6e1e   wdenk   Initial revision
196
  }
67d668bf9   Mike Frysinger   autostart: unify ...
197
198
  int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
  {
00caae6d4   Simon Glass   env: Rename geten...
199
  	const char *ep = env_get("autostart");
67d668bf9   Mike Frysinger   autostart: unify ...
200
201
202
203
204
205
206
207
208
209
210
211
  
  	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;
  }
088f1b199   Kim Phillips   common/cmd_*.c: s...
212
213
  #ifdef CONFIG_SYS_LONGHELP
  static char bootm_help_text[] =
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
214
215
216
217
218
219
220
  	"[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...
221
  #if defined(CONFIG_OF_LIBFDT)
98a9c4d46   Matthew McClintock   * Modify bootm co...
222
223
  	"\tWhen booting a Linux kernel which requires a flat device-tree
  "
5441f61a3   Detlev Zundel   Fix two typos.
224
225
  	"\ta third argument is required which is the address of the
  "
98a9c4d46   Matthew McClintock   * Modify bootm co...
226
227
228
229
230
231
  	"\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...
232
  #endif
6986a3856   Marian Balakowicz   [new uImage] Add ...
233
234
235
236
  #if defined(CONFIG_FIT)
  	"\t
  For the new multi component uImage format (FIT) addresses
  "
da1a3bd4d   Vagrant Cascadian   Fix spelling of "...
237
238
  	"\tmust be extended to include component or configuration unit name:
  "
6986a3856   Marian Balakowicz   [new uImage] Add ...
239
240
241
242
243
244
245
246
247
  	"\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...
248
249
250
251
252
253
254
255
256
257
  	"
  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...
258
  #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
49c3a861d   Kumar Gala   bootm: Add subcom...
259
260
261
262
263
264
265
  	"\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...
266
267
  	"\tcmdline - OS specific command line processing/setup
  "
224c90d10   Peter Tyser   bootm: Fix help m...
268
269
  	"\tbdt     - OS specific bd_t processing
  "
49c3a861d   Kumar Gala   bootm: Add subcom...
270
271
  	"\tprep    - OS specific prep before relocation or go
  "
e3046ba4d   Michal Simek   common: bootm: Do...
272
273
274
275
  #if defined(CONFIG_TRACE)
  	"\tfake    - OS specific fake start without go
  "
  #endif
088f1b199   Kim Phillips   common/cmd_*.c: s...
276
277
278
279
280
281
  	"\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:
282
  );
47d1a6e1e   wdenk   Initial revision
283

1ee1180b6   Marian Balakowicz   [new uImage] Clea...
284
285
286
  /*******************************************************************/
  /* bootd - boot default image */
  /*******************************************************************/
baa26db41   Jon Loeliger   common/cmd_[af]*:...
287
  #if defined(CONFIG_CMD_BOOTD)
712fbcf38   Stephen Warren   checkpatch whites...
288
  int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
47d1a6e1e   wdenk   Initial revision
289
  {
00caae6d4   Simon Glass   env: Rename geten...
290
  	return run_command(env_get("bootcmd"), flag);
47d1a6e1e   wdenk   Initial revision
291
  }
47d1a6e1e   wdenk   Initial revision
292

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

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

47d1a6e1e   wdenk   Initial revision
306
  #endif
47d1a6e1e   wdenk   Initial revision
307

47d1a6e1e   wdenk   Initial revision
308

1ee1180b6   Marian Balakowicz   [new uImage] Clea...
309
310
311
  /*******************************************************************/
  /* iminfo - print header info for a requested image */
  /*******************************************************************/
baa26db41   Jon Loeliger   common/cmd_[af]*:...
312
  #if defined(CONFIG_CMD_IMI)
088f1b199   Kim Phillips   common/cmd_*.c: s...
313
  static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
47d1a6e1e   wdenk   Initial revision
314
315
316
  {
  	int	arg;
  	ulong	addr;
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
317
  	int	rcode = 0;
47d1a6e1e   wdenk   Initial revision
318

47d1a6e1e   wdenk   Initial revision
319
  	if (argc < 2) {
712fbcf38   Stephen Warren   checkpatch whites...
320
  		return image_info(load_addr);
47d1a6e1e   wdenk   Initial revision
321
  	}
47d1a6e1e   wdenk   Initial revision
322

1ee1180b6   Marian Balakowicz   [new uImage] Clea...
323
  	for (arg = 1; arg < argc; ++arg) {
712fbcf38   Stephen Warren   checkpatch whites...
324
325
  		addr = simple_strtoul(argv[arg], NULL, 16);
  		if (image_info(addr) != 0)
1ee1180b6   Marian Balakowicz   [new uImage] Clea...
326
  			rcode = 1;
47d1a6e1e   wdenk   Initial revision
327
328
329
  	}
  	return rcode;
  }
47d1a6e1e   wdenk   Initial revision
330

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

712fbcf38   Stephen Warren   checkpatch whites...
335
336
337
  	printf("
  ## Checking Image at %08lx ...
  ", addr);
47d1a6e1e   wdenk   Initial revision
338

712fbcf38   Stephen Warren   checkpatch whites...
339
  	switch (genimg_get_format(hdr)) {
21d29f7f9   Heiko Schocher   bootm: make use o...
340
  #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
d5934ad77   Marian Balakowicz   [new uImage] Add ...
341
  	case IMAGE_FORMAT_LEGACY:
712fbcf38   Stephen Warren   checkpatch whites...
342
343
344
345
346
  		puts("   Legacy image found
  ");
  		if (!image_check_magic(hdr)) {
  			puts("   Bad Magic Number
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
347
348
  			return 1;
  		}
47d1a6e1e   wdenk   Initial revision
349

712fbcf38   Stephen Warren   checkpatch whites...
350
351
352
  		if (!image_check_hcrc(hdr)) {
  			puts("   Bad Header Checksum
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
353
  			return 1;
47d1a6e1e   wdenk   Initial revision
354
  		}
712fbcf38   Stephen Warren   checkpatch whites...
355
  		image_print_contents(hdr);
47d1a6e1e   wdenk   Initial revision
356

712fbcf38   Stephen Warren   checkpatch whites...
357
358
359
360
  		puts("   Verifying Checksum ... ");
  		if (!image_check_dcrc(hdr)) {
  			puts("   Bad Data CRC
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
361
  			return 1;
47d1a6e1e   wdenk   Initial revision
362
  		}
712fbcf38   Stephen Warren   checkpatch whites...
363
364
  		puts("OK
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
365
  		return 0;
21d29f7f9   Heiko Schocher   bootm: make use o...
366
  #endif
4f1318b29   Michael Trimarchi   common: image: mi...
367
368
369
370
371
372
373
  #if defined(CONFIG_ANDROID_BOOT_IMAGE)
  	case IMAGE_FORMAT_ANDROID:
  		puts("   Android image found
  ");
  		android_print_contents(hdr);
  		return 0;
  #endif
d5934ad77   Marian Balakowicz   [new uImage] Add ...
374
375
  #if defined(CONFIG_FIT)
  	case IMAGE_FORMAT_FIT:
712fbcf38   Stephen Warren   checkpatch whites...
376
377
  		puts("   FIT image found
  ");
47d1a6e1e   wdenk   Initial revision
378

712fbcf38   Stephen Warren   checkpatch whites...
379
380
381
  		if (!fit_check_format(hdr)) {
  			puts("Bad FIT image format!
  ");
e32fea6ad   Marian Balakowicz   [new uImage] Add ...
382
  			return 1;
47d1a6e1e   wdenk   Initial revision
383
  		}
712fbcf38   Stephen Warren   checkpatch whites...
384
  		fit_print_contents(hdr);
a4f243452   Bartlomiej Sieka   FIT: make iminfo ...
385

b8da83665   Simon Glass   image: Rename fit...
386
  		if (!fit_all_image_verify(hdr)) {
712fbcf38   Stephen Warren   checkpatch whites...
387
388
  			puts("Bad hash in FIT image!
  ");
a4f243452   Bartlomiej Sieka   FIT: make iminfo ...
389
390
  			return 1;
  		}
d5934ad77   Marian Balakowicz   [new uImage] Add ...
391
392
393
  		return 0;
  #endif
  	default:
712fbcf38   Stephen Warren   checkpatch whites...
394
395
  		puts("Unknown image format!
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
396
  		break;
47d1a6e1e   wdenk   Initial revision
397
  	}
d5934ad77   Marian Balakowicz   [new uImage] Add ...
398
  	return 1;
47d1a6e1e   wdenk   Initial revision
399
  }
0d4983930   wdenk   Patch by Kenneth ...
400
401
  
  U_BOOT_CMD(
6d0f6bcf3   Jean-Christophe PLAGNIOL-VILLARD   rename CFG_ macro...
402
  	iminfo,	CONFIG_SYS_MAXARGS,	1,	do_iminfo,
2fb2604d5   Peter Tyser   Command usage cle...
403
  	"print header information for application image",
8bde7f776   wdenk   * Code cleanup:
404
405
406
407
408
409
  	"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...
410
  	"      image contents (magic number, header and payload checksums)"
8bde7f776   wdenk   * Code cleanup:
411
  );
25c751e9a   Matthew McClintock   * Support for FDT...
412
  #endif
87a449c8a   Matthew McClintock   Support for FDT i...
413

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

1ee1180b6   Marian Balakowicz   [new uImage] Clea...
415
416
417
  /*******************************************************************/
  /* imls - list all images found in flash */
  /*******************************************************************/
baa26db41   Jon Loeliger   common/cmd_[af]*:...
418
  #if defined(CONFIG_CMD_IMLS)
8fdf1e0f6   Vipin Kumar   imls: Add support...
419
  static int do_imls_nor(void)
27b207fd0   wdenk   * Implement new m...
420
421
422
  {
  	flash_info_t *info;
  	int i, j;
d5934ad77   Marian Balakowicz   [new uImage] Add ...
423
  	void *hdr;
25c751e9a   Matthew McClintock   * Support for FDT...
424

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

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

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

712fbcf38   Stephen Warren   checkpatch whites...
436
  			switch (genimg_get_format(hdr)) {
21d29f7f9   Heiko Schocher   bootm: make use o...
437
  #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
d5934ad77   Marian Balakowicz   [new uImage] Add ...
438
  			case IMAGE_FORMAT_LEGACY:
712fbcf38   Stephen Warren   checkpatch whites...
439
  				if (!image_check_hcrc(hdr))
d5934ad77   Marian Balakowicz   [new uImage] Add ...
440
  					goto next_sector;
712fbcf38   Stephen Warren   checkpatch whites...
441
442
443
  				printf("Legacy Image at %08lX:
  ", (ulong)hdr);
  				image_print_contents(hdr);
d5934ad77   Marian Balakowicz   [new uImage] Add ...
444

712fbcf38   Stephen Warren   checkpatch whites...
445
446
447
448
  				puts("   Verifying Checksum ... ");
  				if (!image_check_dcrc(hdr)) {
  					puts("Bad Data CRC
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
449
  				} else {
712fbcf38   Stephen Warren   checkpatch whites...
450
451
  					puts("OK
  ");
d5934ad77   Marian Balakowicz   [new uImage] Add ...
452
453
  				}
  				break;
21d29f7f9   Heiko Schocher   bootm: make use o...
454
  #endif
d5934ad77   Marian Balakowicz   [new uImage] Add ...
455
456
  #if defined(CONFIG_FIT)
  			case IMAGE_FORMAT_FIT:
712fbcf38   Stephen Warren   checkpatch whites...
457
  				if (!fit_check_format(hdr))
e32fea6ad   Marian Balakowicz   [new uImage] Add ...
458
  					goto next_sector;
712fbcf38   Stephen Warren   checkpatch whites...
459
460
461
  				printf("FIT Image at %08lX:
  ", (ulong)hdr);
  				fit_print_contents(hdr);
d5934ad77   Marian Balakowicz   [new uImage] Add ...
462
  				break;
213bf8c82   Gerald Van Baren   Add a flattened d...
463
  #endif
d5934ad77   Marian Balakowicz   [new uImage] Add ...
464
  			default:
27b207fd0   wdenk   * Implement new m...
465
  				goto next_sector;
25c751e9a   Matthew McClintock   * Support for FDT...
466
  			}
87a449c8a   Matthew McClintock   Support for FDT i...
467

bdccc4fed   wdenk   * Map ISP1362 USB...
468
  next_sector:		;
c76f951a7   Kumar Gala   Added support for...
469
  		}
bdccc4fed   wdenk   * Map ISP1362 USB...
470
  next_bank:	;
27b207fd0   wdenk   * Implement new m...
471
  	}
8fdf1e0f6   Vipin Kumar   imls: Add support...
472
473
474
475
476
  	return 0;
  }
  #endif
  
  #if defined(CONFIG_CMD_IMLS_NAND)
151c06ec6   Scott Wood   mtd: nand: Remove...
477
478
  static int nand_imls_legacyimage(struct mtd_info *mtd, int nand_dev,
  				 loff_t off, size_t len)
8fdf1e0f6   Vipin Kumar   imls: Add support...
479
480
481
482
483
484
485
486
487
488
489
490
491
  {
  	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;
  	}
dbe7881de   Grygorii Strashko   cmd: bootm: fix b...
492
  	ret = nand_read_skip_bad(mtd, off, &len, NULL, mtd->size, imgdata);
8fdf1e0f6   Vipin Kumar   imls: Add support...
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
  	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;
  }
151c06ec6   Scott Wood   mtd: nand: Remove...
520
521
  static int nand_imls_fitimage(struct mtd_info *mtd, int nand_dev, loff_t off,
  			      size_t len)
8fdf1e0f6   Vipin Kumar   imls: Add support...
522
523
524
525
526
527
528
529
530
531
532
533
534
  {
  	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;
  	}
dbe7881de   Grygorii Strashko   cmd: bootm: fix b...
535
  	ret = nand_read_skip_bad(mtd, off, &len, NULL, mtd->size, imgdata);
8fdf1e0f6   Vipin Kumar   imls: Add support...
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
  	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)
  {
151c06ec6   Scott Wood   mtd: nand: Remove...
557
  	struct mtd_info *mtd;
8fdf1e0f6   Vipin Kumar   imls: Add support...
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
  	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++) {
f370b5151   Grygorii Strashko   cmd: bootm: use g...
574
  		mtd = get_nand_dev_by_index(nand_dev);
151c06ec6   Scott Wood   mtd: nand: Remove...
575
  		if (!mtd->name || !mtd->size)
8fdf1e0f6   Vipin Kumar   imls: Add support...
576
  			continue;
151c06ec6   Scott Wood   mtd: nand: Remove...
577
  		for (off = 0; off < mtd->size; off += mtd->erasesize) {
8fdf1e0f6   Vipin Kumar   imls: Add support...
578
579
  			const image_header_t *header;
  			int ret;
151c06ec6   Scott Wood   mtd: nand: Remove...
580
  			if (nand_block_isbad(mtd, off))
8fdf1e0f6   Vipin Kumar   imls: Add support...
581
582
583
  				continue;
  
  			len = sizeof(buffer);
151c06ec6   Scott Wood   mtd: nand: Remove...
584
  			ret = nand_read(mtd, off, &len, (u8 *)buffer);
8fdf1e0f6   Vipin Kumar   imls: Add support...
585
586
587
588
589
590
591
592
  			if (ret < 0 && ret != -EUCLEAN) {
  				printf("NAND read error %d at offset %08llX
  ",
  						ret, off);
  				continue;
  			}
  
  			switch (genimg_get_format(buffer)) {
21d29f7f9   Heiko Schocher   bootm: make use o...
593
  #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
8fdf1e0f6   Vipin Kumar   imls: Add support...
594
595
596
597
  			case IMAGE_FORMAT_LEGACY:
  				header = (const image_header_t *)buffer;
  
  				len = image_get_image_size(header);
151c06ec6   Scott Wood   mtd: nand: Remove...
598
  				nand_imls_legacyimage(mtd, nand_dev, off, len);
8fdf1e0f6   Vipin Kumar   imls: Add support...
599
  				break;
21d29f7f9   Heiko Schocher   bootm: make use o...
600
  #endif
8fdf1e0f6   Vipin Kumar   imls: Add support...
601
602
603
  #if defined(CONFIG_FIT)
  			case IMAGE_FORMAT_FIT:
  				len = fit_get_size(buffer);
151c06ec6   Scott Wood   mtd: nand: Remove...
604
  				nand_imls_fitimage(mtd, nand_dev, off, len);
8fdf1e0f6   Vipin Kumar   imls: Add support...
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
  				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...
633

27b207fd0   wdenk   * Implement new m...
634
635
  	return (0);
  }
c76f951a7   Kumar Gala   Added support for...
636

27b207fd0   wdenk   * Implement new m...
637
638
  U_BOOT_CMD(
  	imls,	1,		1,	do_imls,
2fb2604d5   Peter Tyser   Command usage cle...
639
  	"list all images found in flash",
27b207fd0   wdenk   * Implement new m...
640
641
  	"
  "
8fdf1e0f6   Vipin Kumar   imls: Add support...
642
643
644
  	"    - Prints information about all images found at sector/block
  "
  	"      boundaries in nor/nand flash."
27b207fd0   wdenk   * Implement new m...
645
  );
98a9c4d46   Matthew McClintock   * Modify bootm co...
646
  #endif