2 * (C) Copyright 2000-2011
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
11 #if defined(CONFIG_CMD_IDE) || defined(CONFIG_CMD_SCSI) || \
12 defined(CONFIG_USB_STORAGE)
13 int common_diskboot(cmd_tbl_t
*cmdtp
, const char *intf
, int argc
,
17 ulong addr
= CONFIG_SYS_LOAD_ADDR
;
19 disk_partition_t info
;
20 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
23 block_dev_desc_t
*dev_desc
;
25 #if defined(CONFIG_FIT)
26 const void *fit_hdr
= NULL
;
29 bootstage_mark(BOOTSTAGE_ID_IDE_START
);
31 bootstage_error(BOOTSTAGE_ID_IDE_ADDR
);
34 bootstage_mark(BOOTSTAGE_ID_IDE_ADDR
);
37 addr
= simple_strtoul(argv
[1], NULL
, 16);
39 bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE
);
41 part
= get_device_and_partition(intf
, (argc
== 3) ? argv
[2] : NULL
,
44 bootstage_error(BOOTSTAGE_ID_IDE_TYPE
);
49 bootstage_mark(BOOTSTAGE_ID_IDE_TYPE
);
51 printf("\nLoading from %s device %d, partition %d: "
52 "Name: %.32s Type: %.32s\n", intf
, dev
, part
, info
.name
,
55 debug("First Block: " LBAFU
", # of blocks: " LBAFU
56 ", Block Size: %ld\n",
57 info
.start
, info
.size
, info
.blksz
);
59 if (dev_desc
->block_read(dev
, info
.start
, 1, (ulong
*) addr
) != 1) {
60 printf("** Read error on %d:%d\n", dev
, part
);
61 bootstage_error(BOOTSTAGE_ID_IDE_PART_READ
);
64 bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ
);
66 switch (genimg_get_format((void *) addr
)) {
67 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
68 case IMAGE_FORMAT_LEGACY
:
69 hdr
= (image_header_t
*) addr
;
71 bootstage_mark(BOOTSTAGE_ID_IDE_FORMAT
);
73 if (!image_check_hcrc(hdr
)) {
74 puts("\n** Bad Header Checksum **\n");
75 bootstage_error(BOOTSTAGE_ID_IDE_CHECKSUM
);
78 bootstage_mark(BOOTSTAGE_ID_IDE_CHECKSUM
);
80 image_print_contents(hdr
);
82 cnt
= image_get_image_size(hdr
);
85 #if defined(CONFIG_FIT)
86 case IMAGE_FORMAT_FIT
:
87 fit_hdr
= (const void *) addr
;
88 puts("Fit image detected...\n");
90 cnt
= fit_get_size(fit_hdr
);
94 bootstage_error(BOOTSTAGE_ID_IDE_FORMAT
);
95 puts("** Unknown image type\n");
99 cnt
+= info
.blksz
- 1;
103 if (dev_desc
->block_read(dev
, info
.start
+ 1, cnt
,
104 (ulong
*)(addr
+ info
.blksz
)) != cnt
) {
105 printf("** Read error on %d:%d\n", dev
, part
);
106 bootstage_error(BOOTSTAGE_ID_IDE_READ
);
109 bootstage_mark(BOOTSTAGE_ID_IDE_READ
);
111 #if defined(CONFIG_FIT)
112 /* This cannot be done earlier,
113 * we need complete FIT image in RAM first */
114 if (genimg_get_format((void *) addr
) == IMAGE_FORMAT_FIT
) {
115 if (!fit_check_format(fit_hdr
)) {
116 bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ
);
117 puts("** Bad FIT image format\n");
120 bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK
);
121 fit_print_contents(fit_hdr
);
125 flush_cache(addr
, (cnt
+1)*info
.blksz
);
127 /* Loading ok, update default load address */
130 return bootm_maybe_autostart(cmdtp
, argv
[0]);