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;
21 block_dev_desc_t *dev_desc;
23 #if defined(CONFIG_FIT)
24 const void *fit_hdr = NULL;
27 bootstage_mark(BOOTSTAGE_ID_IDE_START);
29 bootstage_error(BOOTSTAGE_ID_IDE_ADDR);
32 bootstage_mark(BOOTSTAGE_ID_IDE_ADDR);
35 addr = simple_strtoul(argv[1], NULL, 16);
37 bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
39 part = get_device_and_partition(intf, (argc == 3) ? argv[2] : NULL,
42 bootstage_error(BOOTSTAGE_ID_IDE_TYPE);
47 bootstage_mark(BOOTSTAGE_ID_IDE_TYPE);
49 printf("\nLoading from %s device %d, partition %d: "
50 "Name: %.32s Type: %.32s\n", intf, dev, part, info.name,
53 debug("First Block: " LBAFU ", # of blocks: " LBAFU
54 ", Block Size: %ld\n",
55 info.start, info.size, info.blksz);
57 if (dev_desc->block_read(dev, info.start, 1, (ulong *) addr) != 1) {
58 printf("** Read error on %d:%d\n", dev, part);
59 bootstage_error(BOOTSTAGE_ID_IDE_PART_READ);
62 bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ);
64 switch (genimg_get_format((void *) addr)) {
65 case IMAGE_FORMAT_LEGACY:
66 hdr = (image_header_t *) addr;
68 bootstage_mark(BOOTSTAGE_ID_IDE_FORMAT);
70 if (!image_check_hcrc(hdr)) {
71 puts("\n** Bad Header Checksum **\n");
72 bootstage_error(BOOTSTAGE_ID_IDE_CHECKSUM);
75 bootstage_mark(BOOTSTAGE_ID_IDE_CHECKSUM);
77 image_print_contents(hdr);
79 cnt = image_get_image_size(hdr);
81 #if defined(CONFIG_FIT)
82 case IMAGE_FORMAT_FIT:
83 fit_hdr = (const void *) addr;
84 puts("Fit image detected...\n");
86 cnt = fit_get_size(fit_hdr);
90 bootstage_error(BOOTSTAGE_ID_IDE_FORMAT);
91 puts("** Unknown image type\n");
95 cnt += info.blksz - 1;
99 if (dev_desc->block_read(dev, info.start + 1, cnt,
100 (ulong *)(addr + info.blksz)) != cnt) {
101 printf("** Read error on %d:%d\n", dev, part);
102 bootstage_error(BOOTSTAGE_ID_IDE_READ);
105 bootstage_mark(BOOTSTAGE_ID_IDE_READ);
107 #if defined(CONFIG_FIT)
108 /* This cannot be done earlier,
109 * we need complete FIT image in RAM first */
110 if (genimg_get_format((void *) addr) == IMAGE_FORMAT_FIT) {
111 if (!fit_check_format(fit_hdr)) {
112 bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ);
113 puts("** Bad FIT image format\n");
116 bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK);
117 fit_print_contents(fit_hdr);
121 flush_cache(addr, (cnt+1)*info.blksz);
123 /* Loading ok, update default load address */
126 return bootm_maybe_autostart(cmdtp, argv[0]);