2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2012-09-21 04:02:30 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000-2011
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:00 +00:00
|
|
|
#include <bootstage.h>
|
2012-09-21 04:02:30 +00:00
|
|
|
#include <command.h>
|
2019-11-14 19:57:39 +00:00
|
|
|
#include <cpu_func.h>
|
2019-12-28 17:45:03 +00:00
|
|
|
#include <image.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2012-08-23 11:31:48 +00:00
|
|
|
#include <part.h>
|
2012-09-21 04:02:30 +00:00
|
|
|
|
2020-05-10 17:40:03 +00:00
|
|
|
int common_diskboot(struct cmd_tbl *cmdtp, const char *intf, int argc,
|
2012-09-21 04:02:30 +00:00
|
|
|
char *const argv[])
|
|
|
|
{
|
2016-04-30 22:35:54 +00:00
|
|
|
__maybe_unused int dev;
|
|
|
|
int part;
|
2012-08-23 11:31:48 +00:00
|
|
|
ulong addr = CONFIG_SYS_LOAD_ADDR;
|
|
|
|
ulong cnt;
|
2020-05-10 17:39:57 +00:00
|
|
|
struct disk_partition info;
|
2019-05-23 11:14:07 +00:00
|
|
|
#if defined(CONFIG_LEGACY_IMAGE_FORMAT)
|
2022-09-07 02:26:52 +00:00
|
|
|
struct legacy_img_hdr *hdr;
|
2014-05-28 09:33:33 +00:00
|
|
|
#endif
|
2016-02-29 22:25:34 +00:00
|
|
|
struct blk_desc *dev_desc;
|
2012-09-21 04:02:30 +00:00
|
|
|
|
2016-02-23 05:55:43 +00:00
|
|
|
#if CONFIG_IS_ENABLED(FIT)
|
2012-09-21 04:02:30 +00:00
|
|
|
const void *fit_hdr = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_START);
|
2012-08-23 11:31:48 +00:00
|
|
|
if (argc > 3) {
|
2012-09-21 04:02:30 +00:00
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_ADDR);
|
|
|
|
return CMD_RET_USAGE;
|
|
|
|
}
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_ADDR);
|
|
|
|
|
2012-08-23 11:31:48 +00:00
|
|
|
if (argc > 1)
|
2021-07-24 15:03:29 +00:00
|
|
|
addr = hextoul(argv[1], NULL);
|
2012-09-21 04:02:30 +00:00
|
|
|
|
2012-08-23 11:31:48 +00:00
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
|
2012-09-21 04:02:30 +00:00
|
|
|
|
2023-11-18 21:05:20 +00:00
|
|
|
part = blk_get_device_part_str(intf, cmd_arg2(argc, argv),
|
|
|
|
&dev_desc, &info, 1);
|
2012-08-23 11:31:48 +00:00
|
|
|
if (part < 0) {
|
2012-09-21 04:02:30 +00:00
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_TYPE);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-02-29 22:25:51 +00:00
|
|
|
dev = dev_desc->devnum;
|
2012-08-23 11:31:48 +00:00
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_TYPE);
|
2012-09-21 04:02:30 +00:00
|
|
|
|
2012-08-23 11:31:48 +00:00
|
|
|
printf("\nLoading from %s device %d, partition %d: "
|
|
|
|
"Name: %.32s Type: %.32s\n", intf, dev, part, info.name,
|
|
|
|
info.type);
|
2012-09-21 04:02:30 +00:00
|
|
|
|
2013-06-26 16:11:25 +00:00
|
|
|
debug("First Block: " LBAFU ", # of blocks: " LBAFU
|
|
|
|
", Block Size: %ld\n",
|
2012-09-21 04:02:30 +00:00
|
|
|
info.start, info.size, info.blksz);
|
|
|
|
|
2016-02-29 22:25:52 +00:00
|
|
|
if (blk_dread(dev_desc, info.start, 1, (ulong *)addr) != 1) {
|
2012-09-21 04:02:30 +00:00
|
|
|
printf("** Read error on %d:%d\n", dev, part);
|
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_PART_READ);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ);
|
|
|
|
|
|
|
|
switch (genimg_get_format((void *) addr)) {
|
2019-05-23 11:14:07 +00:00
|
|
|
#if defined(CONFIG_LEGACY_IMAGE_FORMAT)
|
2012-09-21 04:02:30 +00:00
|
|
|
case IMAGE_FORMAT_LEGACY:
|
2022-09-07 02:26:52 +00:00
|
|
|
hdr = (struct legacy_img_hdr *)addr;
|
2012-09-21 04:02:30 +00:00
|
|
|
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_FORMAT);
|
|
|
|
|
|
|
|
if (!image_check_hcrc(hdr)) {
|
|
|
|
puts("\n** Bad Header Checksum **\n");
|
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_CHECKSUM);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_CHECKSUM);
|
|
|
|
|
|
|
|
image_print_contents(hdr);
|
|
|
|
|
|
|
|
cnt = image_get_image_size(hdr);
|
|
|
|
break;
|
2014-05-28 09:33:33 +00:00
|
|
|
#endif
|
2016-02-23 05:55:43 +00:00
|
|
|
#if CONFIG_IS_ENABLED(FIT)
|
2012-09-21 04:02:30 +00:00
|
|
|
case IMAGE_FORMAT_FIT:
|
|
|
|
fit_hdr = (const void *) addr;
|
|
|
|
puts("Fit image detected...\n");
|
|
|
|
|
|
|
|
cnt = fit_get_size(fit_hdr);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_FORMAT);
|
|
|
|
puts("** Unknown image type\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cnt += info.blksz - 1;
|
|
|
|
cnt /= info.blksz;
|
|
|
|
cnt -= 1;
|
|
|
|
|
2016-02-29 22:25:52 +00:00
|
|
|
if (blk_dread(dev_desc, info.start + 1, cnt,
|
|
|
|
(ulong *)(addr + info.blksz)) != cnt) {
|
2012-09-21 04:02:30 +00:00
|
|
|
printf("** Read error on %d:%d\n", dev, part);
|
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_READ);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_READ);
|
|
|
|
|
2016-02-23 05:55:43 +00:00
|
|
|
#if CONFIG_IS_ENABLED(FIT)
|
2012-09-21 04:02:30 +00:00
|
|
|
/* This cannot be done earlier,
|
|
|
|
* we need complete FIT image in RAM first */
|
|
|
|
if (genimg_get_format((void *) addr) == IMAGE_FORMAT_FIT) {
|
2021-02-16 00:08:09 +00:00
|
|
|
if (fit_check_format(fit_hdr, IMAGE_SIZE_INVAL)) {
|
2012-09-21 04:02:30 +00:00
|
|
|
bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ);
|
|
|
|
puts("** Bad FIT image format\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
flush_cache(addr, (cnt+1)*info.blksz);
|
|
|
|
|
|
|
|
/* Loading ok, update default load address */
|
2019-12-28 17:45:02 +00:00
|
|
|
image_load_addr = addr;
|
2012-09-21 04:02:30 +00:00
|
|
|
|
|
|
|
return bootm_maybe_autostart(cmdtp, argv[0]);
|
|
|
|
}
|