]> git.sur5r.net Git - u-boot/blobdiff - common/cmd_scsi.c
Add GIT version information (commid ID) to untagged U-Boot versions
[u-boot] / common / cmd_scsi.c
index 9b5c69b32b4712510e3f7d060ba62735111b4adb..e8048611f93b2ff615d18cc41807a2cb6610677b 100644 (file)
 /*
  * SCSI support.
  */
-
 #include <common.h>
 #include <command.h>
-#include <cmd_boot.h>
 #include <asm/processor.h>
 #include <scsi.h>
 #include <image.h>
-#include <cmd_disk.h>
 #include <pci.h>
 
-
-#undef SCSI_DEBUG
-
-#ifdef SCSI_DEBUG
-#define        PRINTF(fmt,args...)     printf (fmt ,##args)
-#else
-#define PRINTF(fmt,args...)
-#endif
-
 #if (CONFIG_COMMANDS & CFG_CMD_SCSI)
 
 #ifdef CONFIG_SCSI_SYM53C8XX
@@ -122,7 +110,7 @@ void scsi_scan(int mode)
                        scsi_setup_inquiry(pccb);
                        if(scsi_exec(pccb)!=TRUE) {
                                if(pccb->contr_stat==SCSI_SEL_TIME_OUT) {
-                                       PRINTF("Selection timeout ID %d\n",pccb->target);
+                                       debug ("Selection timeout ID %d\n",pccb->target);
                                        continue; /* selection timeout => assuming no device present */
                                }
                                scsi_print_error(pccb);
@@ -181,7 +169,6 @@ removable:
 }
 
 
-
 void scsi_init(void)
 {
        int busdevfunc;
@@ -206,7 +193,6 @@ block_dev_desc_t * scsi_get_dev(int dev)
 }
 
 
-
 /******************************************************************************
  * scsi boot command intepreter. Derived from diskboot
  */
@@ -215,8 +201,7 @@ int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        char *boot_device = NULL;
        char *ep;
        int dev, part = 0;
-       ulong cnt;
-       ulong addr;
+       ulong addr, cnt, checksum;
        disk_partition_t info;
        image_header_t *hdr;
        int rcode = 0;
@@ -258,11 +243,12 @@ int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                }
                part = simple_strtoul(++ep, NULL, 16);
        }
-       if (get_partition_info (&scsi_dev_desc[dev], part, &info)) {
+       if (get_partition_info (scsi_dev_desc, part, &info)) {
                printf("error reading partinfo\n");
                return 1;
        }
-       if (strncmp(info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) {
+       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);
@@ -273,7 +259,7 @@ int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                "Name: %.32s  Type: %.32s\n",
                dev, part, info.name, info.type);
 
-       PRINTF ("First Block: %ld,  # of blocks: %ld, Block Size: %ld\n",
+       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) {
@@ -283,18 +269,26 @@ int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
        hdr = (image_header_t *)addr;
 
-       if (hdr->ih_magic == IH_MAGIC) {
-
-               print_image_hdr (hdr);
-               cnt = (hdr->ih_size + sizeof(image_header_t));
-               cnt += info.blksz - 1;
-               cnt /= info.blksz;
-               cnt -= 1;
-       } else {
+       if (ntohl(hdr->ih_magic) == IH_MAGIC) {
                printf("\n** Bad Magic Number **\n");
                return 1;
        }
 
+       checksum = ntohl(hdr->ih_hcrc);
+       hdr->ih_hcrc = 0;
+
+       if (crc32 (0, (uchar *)hdr, sizeof(image_header_t)) != checksum) {
+               puts ("\n** Bad Header Checksum **\n");
+               return 1;
+       }
+       hdr->ih_hcrc = htonl(checksum); /* restore checksum for later use */
+
+       print_image_hdr (hdr);
+       cnt = (ntohl(hdr->ih_size) + sizeof(image_header_t));
+       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);
@@ -362,7 +356,7 @@ int do_scsi (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                                                ok++;
                                                if (dev)
                                                        printf("\n");
-                                               PRINTF("print_part of %x\n",dev);
+                                               debug ("print_part of %x\n",dev);
                                                        print_part(&scsi_dev_desc[dev]);
                                        }
                                }
@@ -438,7 +432,7 @@ ulong scsi_read(int device, ulong blknr, ulong blkcnt, ulong *buffer)
        buf_addr=(unsigned long)buffer;
        start=blknr;
        blks=blkcnt;
-       PRINTF("\nscsi_read: dev %d startblk %lx, blccnt %lx buffer %lx\n",device,start,blks,(unsigned long)buffer);
+       debug ("\nscsi_read: dev %d startblk %lx, blccnt %lx buffer %lx\n",device,start,blks,(unsigned long)buffer);
        do {
                pccb->pdata=(unsigned char *)buf_addr;
                if(blks>SCSI_MAX_READ_BLK) {
@@ -455,7 +449,7 @@ ulong scsi_read(int device, ulong blknr, ulong blkcnt, ulong *buffer)
                        start+=blks;
                        blks=0;
                }
-               PRINTF("scsi_read_ext: startblk %lx, blccnt %x buffer %lx\n",start,smallblks,buf_addr);
+               debug ("scsi_read_ext: startblk %lx, blccnt %x buffer %lx\n",start,smallblks,buf_addr);
                if(scsi_exec(pccb)!=TRUE) {
                        scsi_print_error(pccb);
                        blkcnt-=blks;
@@ -463,7 +457,7 @@ ulong scsi_read(int device, ulong blknr, ulong blkcnt, ulong *buffer)
                }
                buf_addr+=pccb->datalen;
        } while(blks!=0);
-       PRINTF("scsi_read_ext: end startblk %lx, blccnt %x buffer %lx\n",start,smallblks,buf_addr);
+       debug ("scsi_read_ext: end startblk %lx, blccnt %x buffer %lx\n",start,smallblks,buf_addr);
        return(blkcnt);
 }
 
@@ -493,7 +487,6 @@ void scsi_ident_cpy (unsigned char *dest, unsigned char *src, unsigned int len)
 }
 
 
-
 /* Trim trailing blanks, and NUL-terminate string
  */
 void scsi_trim_trail (unsigned char *str, unsigned int len)
@@ -555,7 +548,7 @@ void scsi_setup_read_ext(ccb * pccb, unsigned long start, unsigned short blocks)
        pccb->cmd[6]=0;
        pccb->cmdlen=10;
        pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */
-       PRINTF("scsi_setup_read_ext: cmd: %02X %02X startblk %02X%02X%02X%02X blccnt %02X%02X\n",
+       debug ("scsi_setup_read_ext: cmd: %02X %02X startblk %02X%02X%02X%02X blccnt %02X%02X\n",
                pccb->cmd[0],pccb->cmd[1],
                pccb->cmd[2],pccb->cmd[3],pccb->cmd[4],pccb->cmd[5],
                pccb->cmd[7],pccb->cmd[8]);
@@ -571,7 +564,7 @@ void scsi_setup_read6(ccb * pccb, unsigned long start, unsigned short blocks)
        pccb->cmd[5]=0;
        pccb->cmdlen=6;
        pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */
-       PRINTF("scsi_setup_read6: cmd: %02X %02X startblk %02X%02X blccnt %02X\n",
+       debug ("scsi_setup_read6: cmd: %02X %02X startblk %02X%02X blccnt %02X\n",
                pccb->cmd[0],pccb->cmd[1],
                pccb->cmd[2],pccb->cmd[3],pccb->cmd[4]);
 }
@@ -592,6 +585,23 @@ void scsi_setup_inquiry(ccb * pccb)
        pccb->msgout[0]=SCSI_IDENTIFY; /* NOT USED */
 }
 
-#endif /* #if (CONFIG_COMMANDS & CFG_CMD_SCSI) */
 
+U_BOOT_CMD(
+       scsi, 5, 1, do_scsi,
+       "scsi    - SCSI sub-system\n",
+       "reset - reset SCSI controller\n"
+       "scsi info  - show available SCSI devices\n"
+       "scsi scan  - (re-)scan SCSI bus\n"
+       "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"
+);
+
+U_BOOT_CMD(
+       scsiboot, 3, 1, do_scsiboot,
+       "scsiboot- boot from SCSI device\n",
+       "loadAddr dev:part\n"
+);
 
+#endif /* #if (CONFIG_COMMANDS & CFG_CMD_SCSI) */