]> git.ipfire.org Git - thirdparty/u-boot.git/blobdiff - cmd/fastboot.c
Init virtio before loading ENV from EXT4 or FAT
[thirdparty/u-boot.git] / cmd / fastboot.c
index e6ae0570d5b2f29bc4f8125c78603cac7f6fa126..d4cfc0c7a282b8697f50c207fa8cb46171797ee1 100644 (file)
@@ -6,19 +6,27 @@
  * (C) Copyright 2014 Linaro, Ltd.
  * Rob Herring <robh@kernel.org>
  */
-#include <common.h>
 #include <command.h>
 #include <console.h>
 #include <g_dnl.h>
 #include <fastboot.h>
 #include <net.h>
 #include <usb.h>
+#include <watchdog.h>
+#include <linux/printk.h>
+#include <linux/stringify.h>
 
 static int do_fastboot_udp(int argc, char *const argv[],
                           uintptr_t buf_addr, size_t buf_size)
 {
-#if CONFIG_IS_ENABLED(UDP_FUNCTION_FASTBOOT)
-       int err = net_loop(FASTBOOT);
+       int err;
+
+       if (!IS_ENABLED(CONFIG_UDP_FUNCTION_FASTBOOT)) {
+               pr_err("Fastboot UDP not enabled\n");
+               return CMD_RET_FAILURE;
+       }
+
+       err = net_loop(FASTBOOT_UDP);
 
        if (err < 0) {
                printf("fastboot udp error: %d\n", err);
@@ -26,27 +34,53 @@ static int do_fastboot_udp(int argc, char *const argv[],
        }
 
        return CMD_RET_SUCCESS;
-#else
-       pr_err("Fastboot UDP not enabled\n");
-       return CMD_RET_FAILURE;
-#endif
+}
+
+static int do_fastboot_tcp(int argc, char *const argv[],
+                          uintptr_t buf_addr, size_t buf_size)
+{
+       int err;
+
+       if (!IS_ENABLED(CONFIG_TCP_FUNCTION_FASTBOOT)) {
+               pr_err("Fastboot TCP not enabled\n");
+               return CMD_RET_FAILURE;
+       }
+
+       err = net_loop(FASTBOOT_TCP);
+
+       if (err < 0) {
+               printf("fastboot tcp error: %d\n", err);
+               return CMD_RET_FAILURE;
+       }
+
+       return CMD_RET_SUCCESS;
 }
 
 static int do_fastboot_usb(int argc, char *const argv[],
                           uintptr_t buf_addr, size_t buf_size)
 {
-#if CONFIG_IS_ENABLED(USB_FUNCTION_FASTBOOT)
        int controller_index;
        char *usb_controller;
+       struct udevice *udc;
+       char *endp;
        int ret;
 
+       if (!IS_ENABLED(CONFIG_USB_FUNCTION_FASTBOOT)) {
+               pr_err("Fastboot USB not enabled\n");
+               return CMD_RET_FAILURE;
+       }
+
        if (argc < 2)
                return CMD_RET_USAGE;
 
        usb_controller = argv[1];
-       controller_index = simple_strtoul(usb_controller, NULL, 0);
+       controller_index = simple_strtoul(usb_controller, &endp, 0);
+       if (*endp != '\0') {
+               pr_err("Error: Wrong USB controller index format\n");
+               return CMD_RET_FAILURE;
+       }
 
-       ret = board_usb_init(controller_index, USB_INIT_DEVICE);
+       ret = udc_device_get_by_index(controller_index, &udc);
        if (ret) {
                pr_err("USB init failed: %d\n", ret);
                return CMD_RET_FAILURE;
@@ -69,24 +103,22 @@ static int do_fastboot_usb(int argc, char *const argv[],
                        break;
                if (ctrlc())
                        break;
-               usb_gadget_handle_interrupts(controller_index);
+               schedule();
+               dm_usb_gadget_handle_interrupts(udc);
        }
 
        ret = CMD_RET_SUCCESS;
 
 exit:
+       udc_device_put(udc);
        g_dnl_unregister();
        g_dnl_clear_detach();
-       board_usb_cleanup(controller_index, USB_INIT_DEVICE);
 
        return ret;
-#else
-       pr_err("Fastboot USB not enabled\n");
-       return CMD_RET_FAILURE;
-#endif
 }
 
-static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+static int do_fastboot(struct cmd_tbl *cmdtp, int flag, int argc,
+                      char *const argv[])
 {
        uintptr_t buf_addr = (uintptr_t)NULL;
        size_t buf_size = 0;
@@ -103,13 +135,13 @@ static int do_fastboot(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                        case 'l':
                                if (--argc <= 0)
                                        return CMD_RET_USAGE;
-                               buf_addr = simple_strtoul(*++argv, NULL, 16);
+                               buf_addr = hextoul(*++argv, NULL);
                                goto NXTARG;
 
                        case 's':
                                if (--argc <= 0)
                                        return CMD_RET_USAGE;
-                               buf_size = simple_strtoul(*++argv, NULL, 16);
+                               buf_size = hextoul(*++argv, NULL);
                                goto NXTARG;
 
                        default:
@@ -120,11 +152,18 @@ NXTARG:
                ;
        }
 
+       /* Handle case when USB controller param is just '-' */
+       if (argc == 1) {
+               pr_err("Error: Incorrect USB controller index\n");
+               return CMD_RET_USAGE;
+       }
+
        fastboot_init((void *)buf_addr, buf_size);
 
        if (!strcmp(argv[1], "udp"))
                return do_fastboot_udp(argc, argv, buf_addr, buf_size);
-
+       if (!strcmp(argv[1], "tcp"))
+               return do_fastboot_tcp(argc, argv, buf_addr, buf_size);
        if (!strcmp(argv[1], "usb")) {
                argv++;
                argc--;
@@ -133,17 +172,12 @@ NXTARG:
        return do_fastboot_usb(argc, argv, buf_addr, buf_size);
 }
 
-#ifdef CONFIG_SYS_LONGHELP
-static char fastboot_help_text[] =
+U_BOOT_CMD(
+       fastboot, CONFIG_SYS_MAXARGS, 1, do_fastboot,
+       "run as a fastboot usb or udp device",
        "[-l addr] [-s size] usb <controller> | udp\n"
        "\taddr - address of buffer used during data transfers ("
        __stringify(CONFIG_FASTBOOT_BUF_ADDR) ")\n"
        "\tsize - size of buffer used during data transfers ("
        __stringify(CONFIG_FASTBOOT_BUF_SIZE) ")"
-       ;
-#endif
-
-U_BOOT_CMD(
-       fastboot, CONFIG_SYS_MAXARGS, 1, do_fastboot,
-       "run as a fastboot usb or udp device", fastboot_help_text
 );