]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_scsi.c
scsi: Provide support for a list of AHCI controllers.
[karo-tx-uboot.git] / common / cmd_scsi.c
index dd2c1ae73d6f9e20695be9c08aa5386c34778f63..50eb239aaf6cd964dc9b8d7f52e7c9382dc15ade 100644 (file)
@@ -34,6 +34,9 @@
 #include <image.h>
 #include <pci.h>
 
+#ifdef CONFIG_SCSI_DEV_LIST
+#define SCSI_DEV_LIST CONFIG_SCSI_DEV_LIST
+#else
 #ifdef CONFIG_SCSI_SYM53C8XX
 #define SCSI_VEND_ID   0x1000
 #ifndef CONFIG_SCSI_DEV_ID
 #define SCSI_VEND_ID 0x10b9
 #define SCSI_DEV_ID  0x5288
 
-#else
+#elif !defined(CONFIG_SCSI_AHCI_PLAT)
 #error no scsi device defined
 #endif
+#define SCSI_DEV_LIST {SCSI_VEND_ID, SCSI_DEV_ID}
+#endif
 
-
+#ifdef CONFIG_PCI
+const struct pci_device_id scsi_device_list[] = { SCSI_DEV_LIST };
+#endif
 static ccb tempccb;    /* temporary scsi command buffer */
 
 static unsigned char tempbuff[512]; /* temporary data buffer */
@@ -174,180 +181,75 @@ removable:
                scsi_curr_dev = -1;
 }
 
-
+#ifdef CONFIG_PCI
 void scsi_init(void)
 {
        int busdevfunc;
+       int i;
+       /*
+        * Find a device from the list, this driver will support a single
+        * controller.
+        */
+       for (i = 0; i < ARRAY_SIZE(scsi_device_list); i++) {
+               /* get PCI Device ID */
+               busdevfunc = pci_find_device(scsi_device_list[i].vendor,
+                                            scsi_device_list[i].device,
+                                            0);
+               if (busdevfunc != -1)
+                       break;
+       }
 
-       busdevfunc=pci_find_device(SCSI_VEND_ID,SCSI_DEV_ID,0); /* get PCI Device ID */
-       if(busdevfunc==-1) {
-               printf("Error SCSI Controller (%04X,%04X) not found\n",SCSI_VEND_ID,SCSI_DEV_ID);
+       if (busdevfunc == -1) {
+               printf("Error: SCSI Controller(s) ");
+               for (i = 0; i < ARRAY_SIZE(scsi_device_list); i++) {
+                       printf("%04X:%04X ",
+                              scsi_device_list[i].vendor,
+                              scsi_device_list[i].device);
+               }
+               printf("not found\n");
                return;
        }
 #ifdef DEBUG
        else {
-               printf("SCSI Controller (%04X,%04X) found (%d:%d:%d)\n",SCSI_VEND_ID,SCSI_DEV_ID,(busdevfunc>>16)&0xFF,(busdevfunc>>11)&0x1F,(busdevfunc>>8)&0x7);
+               printf("SCSI Controller (%04X,%04X) found (%d:%d:%d)\n",
+                      scsi_device_list[i].vendor,
+                      scsi_device_list[i].device,
+                      (busdevfunc >> 16) & 0xFF,
+                      (busdevfunc >> 11) & 0x1F,
+                      (busdevfunc >> 8) & 0x7);
        }
 #endif
        scsi_low_level_init(busdevfunc);
        scsi_scan(1);
 }
+#endif
 
+#ifdef CONFIG_PARTITIONS
 block_dev_desc_t * scsi_get_dev(int dev)
 {
        return (dev < CONFIG_SYS_SCSI_MAX_DEVICE) ? &scsi_dev_desc[dev] : NULL;
 }
-
+#endif
 
 /******************************************************************************
  * scsi boot command intepreter. Derived from diskboot
  */
-int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+int do_scsiboot (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;
-       int rcode = 0;
-#if defined(CONFIG_FIT)
-       const void *fit_hdr = NULL;
-#endif
-
-       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:
-               cmd_usage(cmdtp);
-               return 1;
-       }
-
-       if (!boot_device) {
-               puts ("\n** No boot device **\n");
-               return 1;
-       }
-
-       dev = simple_strtoul(boot_device, &ep, 16);
-       printf("booting from dev %d\n",dev);
-       if (scsi_dev_desc[dev].type == DEV_TYPE_UNKNOWN) {
-               printf ("\n** Device %d not available\n", dev);
-               return 1;
-       }
-
-       if (*ep) {
-               if (*ep != ':') {
-                       puts ("\n** Invalid boot device, use `dev[:part]' **\n");
-                       return 1;
-               }
-               part = simple_strtoul(++ep, NULL, 16);
-       }
-       if (get_partition_info (&scsi_dev_desc[dev], part, &info)) {
-               printf("error reading partinfo\n");
-               return 1;
-       }
-       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);
-               return 1;
-       }
-
-       printf ("\nLoading from SCSI 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 (scsi_read (dev, info.start, 1, (ulong *)addr) != 1) {
-               printf ("** Read error on %d:%d\n", dev, part);
-               return 1;
-       }
-
-       switch (genimg_get_format ((void *)addr)) {
-       case IMAGE_FORMAT_LEGACY:
-               hdr = (image_header_t *)addr;
-
-               if (!image_check_hcrc (hdr)) {
-                       puts ("\n** Bad Header Checksum **\n");
-                       return 1;
-               }
-
-               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:
-               puts ("** Unknown image type\n");
-               return 1;
-       }
-
-       cnt += info.blksz - 1;
-       cnt /= info.blksz;
-       cnt -= 1;
-
-       if (scsi_read (dev, info.start+1, cnt,
-                     (ulong *)(addr+info.blksz)) != cnt) {
-               printf ("** Read error on %d:%d\n", dev, part);
-               return 1;
-       }
-
-#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)) {
-                       puts ("** Bad FIT image format\n");
-                       return 1;
-               }
-               fit_print_contents (fit_hdr);
-       }
-#endif
-
-       /* Loading ok, update default load address */
-       load_addr = addr;
-
-       flush_cache (addr, (cnt+1)*info.blksz);
-
-       /* Check if we should attempt an auto-start */
-       if (((ep = getenv("autostart")) != NULL) && (strcmp(ep,"yes") == 0)) {
-               char *local_args[2];
-               extern int do_bootm (cmd_tbl_t *, int, int, char *[]);
-               local_args[0] = argv[0];
-               local_args[1] = NULL;
-               printf ("Automatic boot of image at addr 0x%08lX ...\n", addr);
-               rcode = do_bootm (cmdtp, 0, 1, local_args);
-       }
-        return rcode;
+       return common_diskboot(cmdtp, "scsi", argc, argv);
 }
 
 /*********************************************************************************
  * scsi command intepreter
  */
-int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        switch (argc) {
-    case 0:
-    case 1:    cmd_usage(cmdtp);       return 1;
-    case 2:
+       case 0:
+       case 1:
+               return CMD_RET_USAGE;
+
+       case 2:
                        if (strncmp(argv[1],"res",3) == 0) {
                                printf("\nReset SCSI\n");
                                scsi_bus_reset();
@@ -392,8 +294,7 @@ int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                                        printf("\nno SCSI devices available\n");
                                return 1;
                        }
-                       cmd_usage(cmdtp);
-                       return 1;
+                       return CMD_RET_USAGE;
        case 3:
                        if (strncmp(argv[1],"dev",3) == 0) {
                                int dev = (int)simple_strtoul(argv[2], NULL, 10);
@@ -421,8 +322,7 @@ int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                                }
                                return 1;
                        }
-                       cmd_usage(cmdtp);
-                       return 1;
+                       return CMD_RET_USAGE;
     default:
                        /* at least 4 args */
                        if (strcmp(argv[1],"read") == 0) {
@@ -437,8 +337,7 @@ int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                                return 0;
                        }
        } /* switch */
-       cmd_usage(cmdtp);
-       return 1;
+       return CMD_RET_USAGE;
 }
 
 /****************************************************************************************
@@ -623,11 +522,11 @@ U_BOOT_CMD(
        "scsi device [dev] - show or set current device\n"
        "scsi part [dev] - print partition table of one or all SCSI devices\n"
        "scsi read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
-       "     to memory address `addr'\n"
+       "     to memory address `addr'"
 );
 
 U_BOOT_CMD(
        scsiboot, 3, 1, do_scsiboot,
        "boot from SCSI device",
-       "loadAddr dev:part\n"
+       "loadAddr dev:part"
 );