]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_disk.c
console: Fix pre-console flushing via cfb_console being very slow
[karo-tx-uboot.git] / common / cmd_disk.c
index e73fc4e45692d511dff3c0ecc172dea71b07d415..8a1fda9f68a412a0afa232df5a6e3c0ed7d69890 100644 (file)
@@ -2,37 +2,24 @@
  * (C) Copyright 2000-2011
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- *
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 #include <common.h>
 #include <command.h>
+#include <part.h>
 
+#if defined(CONFIG_CMD_IDE) || defined(CONFIG_CMD_SCSI) || \
+       defined(CONFIG_USB_STORAGE)
 int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
                    char *const argv[])
 {
-       char *boot_device = NULL;
-       char *ep;
-       int dev, part = 0;
-       ulong addr, cnt;
+       int dev, part;
+       ulong addr = CONFIG_SYS_LOAD_ADDR;
+       ulong cnt;
        disk_partition_t info;
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        image_header_t *hdr;
+#endif
        block_dev_desc_t *dev_desc;
 
 #if defined(CONFIG_FIT)
@@ -40,74 +27,33 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
 #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:
+       if (argc > 3) {
                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);
+       if (argc > 1)
+               addr = simple_strtoul(argv[1], NULL, 16);
 
-       dev = simple_strtoul(boot_device, &ep, 16);
+       bootstage_mark(BOOTSTAGE_ID_IDE_BOOT_DEVICE);
 
-       dev_desc = get_dev(intf, dev);
-       if (dev_desc->type == DEV_TYPE_UNKNOWN) {
-               printf("\n** Device %d not available\n", dev);
+       part = get_device_and_partition(intf, (argc == 3) ? argv[2] : NULL,
+                                       &dev_desc, &info, 1);
+       if (part < 0) {
                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(dev_desc, 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);
+       dev = dev_desc->dev;
+       bootstage_mark(BOOTSTAGE_ID_IDE_TYPE);
 
-       printf("\nLoading from disk device %d, partition %d: "
-              "Name: %.32s  Type: %.32s\n", dev, part, info.name, info.type);
+       printf("\nLoading from %s device %d, partition %d: "
+              "Name: %.32s  Type: %.32s\n", intf, dev, part, info.name,
+              info.type);
 
-       debug("First Block: %ld,  # of blocks: %ld, Block Size: %ld\n",
+       debug("First Block: " LBAFU ",  # of blocks: " LBAFU
+             ", Block Size: %ld\n",
              info.start, info.size, info.blksz);
 
        if (dev_desc->block_read(dev, info.start, 1, (ulong *) addr) != 1) {
@@ -118,6 +64,7 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
        bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ);
 
        switch (genimg_get_format((void *) addr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        case IMAGE_FORMAT_LEGACY:
                hdr = (image_header_t *) addr;
 
@@ -134,6 +81,7 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
 
                cnt = image_get_image_size(hdr);
                break;
+#endif
 #if defined(CONFIG_FIT)
        case IMAGE_FORMAT_FIT:
                fit_hdr = (const void *) addr;
@@ -181,3 +129,4 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
 
        return bootm_maybe_autostart(cmdtp, argv[0]);
 }
+#endif