summaryrefslogtreecommitdiff
path: root/common/cmd_ide.c
diff options
context:
space:
mode:
authorRob Herring <rob.herring@calxeda.com>2012-09-21 04:02:30 +0000
committerTom Rini <trini@ti.com>2012-09-25 14:43:19 -0700
commit7405a133101e009c760b98dd4dbcdc49b82ec3b3 (patch)
treef47bc2c471396d8f49c76e5b5424f3afc923485f /common/cmd_ide.c
parent2f5016462710050ce6c052bbc87cba115f53a51f (diff)
downloadu-boot-imx-7405a133101e009c760b98dd4dbcdc49b82ec3b3.zip
u-boot-imx-7405a133101e009c760b98dd4dbcdc49b82ec3b3.tar.gz
u-boot-imx-7405a133101e009c760b98dd4dbcdc49b82ec3b3.tar.bz2
combine block device load commands into common function
All the raw block load commands duplicate the same code. Starting with the ide version as it has progress updates convert ide, usb, and scsi boot commands to all use a common version. Signed-off-by: Rob Herring <rob.herring@calxeda.com>
Diffstat (limited to 'common/cmd_ide.c')
-rw-r--r--common/cmd_ide.c151
1 files changed, 1 insertions, 150 deletions
diff --git a/common/cmd_ide.c b/common/cmd_ide.c
index f5b6c7b..6e1e568 100644
--- a/common/cmd_ide.c
+++ b/common/cmd_ide.c
@@ -334,156 +334,7 @@ int do_ide(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
int do_diskboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
- char *boot_device = NULL;
- char *ep;
- int dev, part = 0;
- ulong addr, cnt;
- disk_partition_t info;
- image_header_t *hdr;
-
-#if defined(CONFIG_FIT)
- const void *fit_hdr = NULL;
-#endif
-
- bootstage_mark(BOOTSTAGE_ID_IDE_START);
- switch (argc) {
- case 1:
- addr = CONFIG_SYS_LOAD_ADDR;
- boot_device = getenv("bootdevice");
- break;
- case 2:
- addr = simple_strtoul(argv[1], NULL, 16);
- boot_device = getenv("bootdevice");
- break;
- case 3:
- addr = simple_strtoul(argv[1], NULL, 16);
- boot_device = argv[2];
- break;
- default:
- bootstage_error(BOOTSTAGE_ID_IDE_ADDR);
- return CMD_RET_USAGE;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_ADDR);
-
- if (!boot_device) {
- puts("\n** No boot device **\n");
- bootstage_error(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
-
- dev = simple_strtoul(boot_device, &ep, 16);
-
- if (ide_dev_desc[dev].type == DEV_TYPE_UNKNOWN) {
- printf("\n** Device %d not available\n", dev);
- bootstage_error(BOOTSTAGE_ID_IDE_TYPE);
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_TYPE);
-
- if (*ep) {
- if (*ep != ':') {
- puts("\n** Invalid boot device, use `dev[:part]' **\n");
- bootstage_error(BOOTSTAGE_ID_IDE_PART);
- return 1;
- }
- part = simple_strtoul(++ep, NULL, 16);
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_PART);
-
- if (get_partition_info(&ide_dev_desc[dev], part, &info)) {
- bootstage_error(BOOTSTAGE_ID_IDE_PART_INFO);
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_PART_INFO);
-
- if ((strncmp((char *)info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0)
- &&
- (strncmp((char *)info.type, BOOT_PART_COMP, sizeof(info.type)) != 0)
- ) {
- printf("\n** Invalid partition type \"%.32s\"" " (expect \""
- BOOT_PART_TYPE "\")\n",
- info.type);
- bootstage_error(BOOTSTAGE_ID_IDE_PART_TYPE);
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_PART_TYPE);
-
- printf("\nLoading from IDE device %d, partition %d: "
- "Name: %.32s Type: %.32s\n", dev, part, info.name, info.type);
-
- debug("First Block: %ld, # of blocks: %ld, Block Size: %ld\n",
- info.start, info.size, info.blksz);
-
- if (ide_dev_desc[dev].
- block_read(dev, info.start, 1, (ulong *) addr) != 1) {
- 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)) {
- case IMAGE_FORMAT_LEGACY:
- hdr = (image_header_t *) addr;
-
- 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;
-#if defined(CONFIG_FIT)
- 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;
-
- if (ide_dev_desc[dev].block_read(dev, info.start + 1, cnt,
- (ulong *)(addr + info.blksz)) != cnt) {
- printf("** Read error on %d:%d\n", dev, part);
- bootstage_error(BOOTSTAGE_ID_IDE_READ);
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_READ);
-
-#if defined(CONFIG_FIT)
- /* This cannot be done earlier, we need complete FIT image in RAM first */
- if (genimg_get_format((void *) addr) == IMAGE_FORMAT_FIT) {
- if (!fit_check_format(fit_hdr)) {
- bootstage_error(BOOTSTAGE_ID_IDE_FIT_READ);
- puts("** Bad FIT image format\n");
- return 1;
- }
- bootstage_mark(BOOTSTAGE_ID_IDE_FIT_READ_OK);
- fit_print_contents(fit_hdr);
- }
-#endif
-
- /* Loading ok, update default load address */
-
- load_addr = addr;
-
- return bootm_maybe_autostart(cmdtp, argv[0]);
+ return common_diskboot(cmdtp, "ide", argc, argv);
}
/* ------------------------------------------------------------------------- */