]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_usb.c
[new uImage] Update naming convention for bootm/uImage related code
[karo-tx-uboot.git] / common / cmd_usb.c
index 8a3f47113f6d9c84d26d84a0b2e6a2ac65b150ce..8ee7d27675eb18393e7cd1b790cb95375ad68194 100644 (file)
 
 #include <common.h>
 #include <command.h>
-
-#if (CONFIG_COMMANDS & CFG_CMD_USB)
-
+#include <asm/byteorder.h>
+#include <part.h>
 #include <usb.h>
-#include <cmd_disk.h>
-
-#undef CMD_USB_DEBUG
 
-#ifdef CMD_USB_DEBUG
-#define        CMD_USB_PRINTF(fmt,args...)     printf (fmt ,##args)
-#else
-#define CMD_USB_PRINTF(fmt,args...)
-#endif
+#ifdef CONFIG_USB_STORAGE
 static int usb_stor_curr_dev=-1; /* current device */
+#endif
 
-/* somme display routines (info command) */
+/* some display routines (info command) */
 char * usb_get_class_desc(unsigned char dclass)
 {
        switch(dclass) {
@@ -191,7 +184,7 @@ void usb_display_conf_desc(struct usb_config_descriptor *config,struct usb_devic
 void usb_display_if_desc(struct usb_interface_descriptor *ifdesc,struct usb_device *dev)
 {
        printf("     Interface: %d\n",ifdesc->bInterfaceNumber);
-       printf("     - Alternate Settings %d, Endpoints: %d\n",ifdesc->bAlternateSetting,ifdesc->bNumEndpoints);
+       printf("     - Alternate Setting %d, Endpoints: %d\n",ifdesc->bAlternateSetting,ifdesc->bNumEndpoints);
        printf("     - Class ");
        usb_display_class_sub(ifdesc->bInterfaceClass,ifdesc->bInterfaceSubClass,ifdesc->bInterfaceProtocol);
        printf("\n");
@@ -309,7 +302,6 @@ void usb_show_tree(struct usb_device *dev)
 }
 
 
-
 /******************************************************************************
  * usb boot command intepreter. Derived from diskboot
  */
@@ -318,9 +310,8 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
        char *boot_device = NULL;
        char *ep;
-       int dev, part=0, rcode;
-       ulong cnt;
-       ulong addr;
+       int dev, part=1, rcode;
+       ulong addr, cnt;
        disk_partition_t info;
        image_header_t *hdr;
        block_dev_desc_t *stor_dev;
@@ -369,15 +360,15 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
        if (get_partition_info (stor_dev, part, &info)) {
                /* try to boot raw .... */
-               strncpy(&info.type[0], BOOT_PART_TYPE, sizeof(BOOT_PART_TYPE));
-               strncpy(&info.name[0], "Raw", 4);
+               strncpy((char *)&info.type[0], BOOT_PART_TYPE, sizeof(BOOT_PART_TYPE));
+               strncpy((char *)&info.name[0], "Raw", 4);
                info.start=0;
                info.blksz=0x200;
                info.size=2880;
                printf("error reading partinfo...try to boot raw\n");
        }
-       if ((strncmp(info.type, BOOT_PART_TYPE, sizeof(info.type)) != 0) &&
-           (strncmp(info.type, BOOT_PART_COMP, 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);
@@ -387,7 +378,7 @@ int do_usbboot (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 (stor_dev->block_read(dev, info.start, 1, (ulong *)addr) != 1) {
@@ -395,19 +386,38 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                return 1;
        }
 
-       hdr = (image_header_t *)addr;
+       switch (genimg_get_format ((void *)addr)) {
+       case IMAGE_FORMAT_LEGACY:
+               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 {
-               printf("\n** Bad Magic Number **\n");
+               if (!image_check_magic (hdr)) {
+                       printf("\n** Bad Magic Number **\n");
+                       return 1;
+               }
+
+               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_unsupported ("usbboot");
+               return 1;
+#endif
+       default:
+               puts ("** Unknown image type\n");
                return 1;
        }
 
+       cnt += info.blksz - 1;
+       cnt /= info.blksz;
+       cnt -= 1;
+
        if (stor_dev->block_read (dev, info.start+1, cnt,
                      (ulong *)(addr+info.blksz)) != cnt) {
                printf ("\n** Read error on %d:%d\n", dev, part);
@@ -433,7 +443,6 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 #endif /* CONFIG_USB_STORAGE */
 
 
-
 /*********************************************************************************
  * usb command intepreter
  */
@@ -442,13 +451,21 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
        int i;
        struct usb_device *dev = NULL;
+       extern char usb_started;
+#ifdef CONFIG_USB_STORAGE
        block_dev_desc_t *stor_dev;
+#endif
 
-       if ((strncmp(argv[1],"reset",5) == 0) ||
-                (strncmp(argv[1],"start",5) == 0)){
+       if ((strncmp(argv[1], "reset", 5) == 0) ||
+                (strncmp(argv[1], "start", 5) == 0)){
                usb_stop();
                printf("(Re)start USB...\n");
-               usb_init();
+               i = usb_init();
+#ifdef CONFIG_USB_STORAGE
+               /* try to recognize storage devices immediately */
+               if (i >= 0)
+                       usb_stor_curr_dev = usb_stor_scan(1);
+#endif
                return 0;
        }
        if (strncmp(argv[1],"stop",4) == 0) {
@@ -468,6 +485,10 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                usb_stop();
                return 0;
        }
+       if (!usb_started) {
+               printf("USB is stopped. Please issue 'usb start' first.\n");
+               return 1;
+       }
        if (strncmp(argv[1],"tree",4) == 0) {
                printf("\nDevice Tree:\n");
                usb_show_tree(usb_get_dev_index(0));
@@ -509,15 +530,18 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                return 0;
        }
 #ifdef CONFIG_USB_STORAGE
-       if (strncmp(argv[1],"scan",4) == 0) {
-               printf("Scan for storage device:\n");
-               usb_stor_curr_dev=usb_stor_scan(1);
-               if (usb_stor_curr_dev==-1) {
-                       printf("No device found. Not initialized?\n");
-                       return 1;
-               }
+       if (strncmp(argv[1], "scan", 4) == 0) {
+               printf("  NOTE: this command is obsolete and will be phased out\n");
+               printf("  please use 'usb storage' for USB storage devices information\n\n");
+               usb_stor_info();
                return 0;
        }
+
+       if (strncmp(argv[1], "stor", 4) == 0) {
+               usb_stor_info();
+               return 0;
+       }
+
        if (strncmp(argv[1],"part",4) == 0) {
                int devno, ok;
                for (ok=0, devno=0; devno<USB_MAX_STOR_DEV; ++devno) {
@@ -556,8 +580,8 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                        return 1;
                }
        }
-       if (strcmp(argv[1],"dev") == 0) {
-               if (argc==3) {
+       if (strncmp(argv[1], "dev", 3) == 0) {
+               if (argc == 3) {
                        int dev = (int)simple_strtoul(argv[2], NULL, 10);
                        printf ("\nUSB device %d: ", dev);
                        if (dev >= USB_MAX_STOR_DEV) {
@@ -590,7 +614,34 @@ int do_usb (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        return 1;
 }
 
+#ifdef CONFIG_USB_STORAGE
+U_BOOT_CMD(
+       usb,    5,      1,      do_usb,
+       "usb     - USB sub-system\n",
+       "reset - reset (rescan) USB controller\n"
+       "usb stop [f]  - stop USB [f]=force stop\n"
+       "usb tree  - show USB device tree\n"
+       "usb info [dev] - show available USB devices\n"
+       "usb storage  - show details of USB storage devices\n"
+       "usb dev [dev] - show or set current USB storage device\n"
+       "usb part [dev] - print partition table of one or all USB storage devices\n"
+       "usb read addr blk# cnt - read `cnt' blocks starting at block `blk#'\n"
+       "    to memory address `addr'\n"
+);
+
+
+U_BOOT_CMD(
+       usbboot,        3,      1,      do_usbboot,
+       "usbboot - boot from USB device\n",
+       "loadAddr dev:part\n"
+);
 
-#endif /* (CONFIG_COMMANDS & CFG_CMD_USB) */
-
-
+#else
+U_BOOT_CMD(
+       usb,    5,      1,      do_usb,
+       "usb     - USB sub-system\n",
+       "reset - reset (rescan) USB controller\n"
+       "usb  tree  - show USB device tree\n"
+       "usb  info [dev] - show available USB devices\n"
+);
+#endif