2 * (C) Copyright 2000-2011
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
11 int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
14 __maybe_unused int dev;
16 ulong addr = CONFIG_SYS_LOAD_ADDR;
18 disk_partition_t info;
19 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
22 struct blk_desc *dev_desc;
24 #if CONFIG_IS_ENABLED(FIT)
25 const void *fit_hdr = NULL;
28 bootstage_mark(BOOTSTAGE_ID_IDE_START);
30 bootstage_error(BOOTSTAGE_ID_IDE_ADDR);
33 bootstage_mark(BOOTSTAGE_ID_IDE_ADDR);
36 addr = simple_strtoul(argv[1], NULL, 16);
38 bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
40 part = blk_get_device_part_str(intf, (argc == 3) ? argv[2] : NULL,
43 bootstage_error(BOOTSTAGE_ID_IDE_TYPE);
47 dev = dev_desc->devnum;
48 bootstage_mark(BOOTSTAGE_ID_IDE_TYPE);
50 printf("\nLoading from %s device %d, partition %d: "
51 "Name: %.32s Type: %.32s\n", intf, dev, part, info.name,
54 debug("First Block: " LBAFU ", # of blocks: " LBAFU
55 ", Block Size: %ld\n",
56 info.start, info.size, info.blksz);
58 if (blk_dread(dev_desc, info.start, 1, (ulong *)addr) != 1) {
59 printf("** Read error on %d:%d\n", dev, part);
60 bootstage_error(BOOTSTAGE_ID_IDE_PART_READ);
63 bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ);
65 switch (genimg_get_format((void *) addr)) {
66 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
67 case IMAGE_FORMAT_LEGACY:
68 hdr = (image_header_t *) addr;
70 bootstage_mark(BOOTSTAGE_ID_IDE_FORMAT);
72 if (!image_check_hcrc(hdr)) {
73 puts("\n** Bad Header Checksum **\n");
74 bootstage_error(BOOTSTAGE_ID_IDE_CHECKSUM);
77 bootstage_mark(BOOTSTAGE_ID_IDE_CHECKSUM);
79 image_print_contents(hdr);
81 cnt = image_get_image_size(hdr);
84 #if CONFIG_IS_ENABLED(FIT)
85 case IMAGE_FORMAT_FIT:
86 fit_hdr = (const void *) addr;
87 puts("Fit image detected...\n");
89 cnt = fit_get_size(fit_hdr);
93 bootstage_error(BOOTSTAGE_ID_IDE_FORMAT);
94 puts("** Unknown image type\n");
98 cnt += info.blksz - 1;
102 if (blk_dread(dev_desc, info.start + 1, cnt,
103 (ulong *)(addr + info.blksz)) != cnt) {
104 printf("** Read error on %d:%d\n", dev, part);
105 bootstage_error(BOOTSTAGE_ID_IDE_READ);
108 bootstage_mark(BOOTSTAGE_ID_IDE_READ);
110 #if CONFIG_IS_ENABLED(FIT)
111 /* This cannot be done earlier,
112 * we need complete FIT image in RAM first */
113 if (genimg_get_format((void *) addr) == IMAGE_FORMAT_FIT) {
114 if (!fit_check_format(fit_hdr)) {
115 bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ);
116 puts("** Bad FIT image format\n");
119 bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK);
120 fit_print_contents(fit_hdr);
124 flush_cache(addr, (cnt+1)*info.blksz);
126 /* Loading ok, update default load address */
129 return bootm_maybe_autostart(cmdtp, argv[0]);