1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2011
13 int common_diskboot(struct cmd_tbl *cmdtp, const char *intf, int argc,
16 __maybe_unused int dev;
18 ulong addr = CONFIG_SYS_LOAD_ADDR;
20 struct disk_partition info;
21 #if defined(CONFIG_LEGACY_IMAGE_FORMAT)
22 struct legacy_img_hdr *hdr;
24 struct blk_desc *dev_desc;
26 #if CONFIG_IS_ENABLED(FIT)
27 const void *fit_hdr = NULL;
30 bootstage_mark(BOOTSTAGE_ID_IDE_START);
32 bootstage_error(BOOTSTAGE_ID_IDE_ADDR);
35 bootstage_mark(BOOTSTAGE_ID_IDE_ADDR);
38 addr = hextoul(argv[1], NULL);
40 bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
42 part = blk_get_device_part_str(intf, cmd_arg2(argc, argv),
45 bootstage_error(BOOTSTAGE_ID_IDE_TYPE);
49 dev = dev_desc->devnum;
50 bootstage_mark(BOOTSTAGE_ID_IDE_TYPE);
52 printf("\nLoading from %s device %d, partition %d: "
53 "Name: %.32s Type: %.32s\n", intf, dev, part, info.name,
56 debug("First Block: " LBAFU ", # of blocks: " LBAFU
57 ", Block Size: %ld\n",
58 info.start, info.size, info.blksz);
60 if (blk_dread(dev_desc, info.start, 1, (ulong *)addr) != 1) {
61 printf("** Read error on %d:%d\n", dev, part);
62 bootstage_error(BOOTSTAGE_ID_IDE_PART_READ);
65 bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ);
67 switch (genimg_get_format((void *) addr)) {
68 #if defined(CONFIG_LEGACY_IMAGE_FORMAT)
69 case IMAGE_FORMAT_LEGACY:
70 hdr = (struct legacy_img_hdr *)addr;
72 bootstage_mark(BOOTSTAGE_ID_IDE_FORMAT);
74 if (!image_check_hcrc(hdr)) {
75 puts("\n** Bad Header Checksum **\n");
76 bootstage_error(BOOTSTAGE_ID_IDE_CHECKSUM);
79 bootstage_mark(BOOTSTAGE_ID_IDE_CHECKSUM);
81 image_print_contents(hdr);
83 cnt = image_get_image_size(hdr);
86 #if CONFIG_IS_ENABLED(FIT)
87 case IMAGE_FORMAT_FIT:
88 fit_hdr = (const void *) addr;
89 puts("Fit image detected...\n");
91 cnt = fit_get_size(fit_hdr);
95 bootstage_error(BOOTSTAGE_ID_IDE_FORMAT);
96 puts("** Unknown image type\n");
100 cnt += info.blksz - 1;
104 if (blk_dread(dev_desc, info.start + 1, cnt,
105 (ulong *)(addr + info.blksz)) != cnt) {
106 printf("** Read error on %d:%d\n", dev, part);
107 bootstage_error(BOOTSTAGE_ID_IDE_READ);
110 bootstage_mark(BOOTSTAGE_ID_IDE_READ);
112 #if CONFIG_IS_ENABLED(FIT)
113 /* This cannot be done earlier,
114 * we need complete FIT image in RAM first */
115 if (genimg_get_format((void *) addr) == IMAGE_FORMAT_FIT) {
116 if (fit_check_format(fit_hdr, IMAGE_SIZE_INVAL)) {
117 bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ);
118 puts("** Bad FIT image format\n");
121 bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK);
125 flush_cache(addr, (cnt+1)*info.blksz);
127 /* Loading ok, update default load address */
128 image_load_addr = addr;
130 return bootm_maybe_autostart(cmdtp, argv[0]);