1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2011
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
10 int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
13 __maybe_unused int dev;
15 ulong addr = CONFIG_SYS_LOAD_ADDR;
17 disk_partition_t info;
18 #if defined(CONFIG_LEGACY_IMAGE_FORMAT)
21 struct blk_desc *dev_desc;
23 #if CONFIG_IS_ENABLED(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 = blk_get_device_part_str(intf, (argc == 3) ? argv[2] : NULL,
42 bootstage_error(BOOTSTAGE_ID_IDE_TYPE);
46 dev = dev_desc->devnum;
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 (blk_dread(dev_desc, 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 #if defined(CONFIG_LEGACY_IMAGE_FORMAT)
66 case IMAGE_FORMAT_LEGACY:
67 hdr = (image_header_t *) addr;
69 bootstage_mark(BOOTSTAGE_ID_IDE_FORMAT);
71 if (!image_check_hcrc(hdr)) {
72 puts("\n** Bad Header Checksum **\n");
73 bootstage_error(BOOTSTAGE_ID_IDE_CHECKSUM);
76 bootstage_mark(BOOTSTAGE_ID_IDE_CHECKSUM);
78 image_print_contents(hdr);
80 cnt = image_get_image_size(hdr);
83 #if CONFIG_IS_ENABLED(FIT)
84 case IMAGE_FORMAT_FIT:
85 fit_hdr = (const void *) addr;
86 puts("Fit image detected...\n");
88 cnt = fit_get_size(fit_hdr);
92 bootstage_error(BOOTSTAGE_ID_IDE_FORMAT);
93 puts("** Unknown image type\n");
97 cnt += info.blksz - 1;
101 if (blk_dread(dev_desc, info.start + 1, cnt,
102 (ulong *)(addr + info.blksz)) != cnt) {
103 printf("** Read error on %d:%d\n", dev, part);
104 bootstage_error(BOOTSTAGE_ID_IDE_READ);
107 bootstage_mark(BOOTSTAGE_ID_IDE_READ);
109 #if CONFIG_IS_ENABLED(FIT)
110 /* This cannot be done earlier,
111 * we need complete FIT image in RAM first */
112 if (genimg_get_format((void *) addr) == IMAGE_FORMAT_FIT) {
113 if (!fit_check_format(fit_hdr)) {
114 bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ);
115 puts("** Bad FIT image format\n");
118 bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK);
119 fit_print_contents(fit_hdr);
123 flush_cache(addr, (cnt+1)*info.blksz);
125 /* Loading ok, update default load address */
128 return bootm_maybe_autostart(cmdtp, argv[0]);