Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 2 | /* |
| 3 | * cmd_dfu.c -- dfu command |
| 4 | * |
Lukasz Majewski | c2c146f | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 5 | * Copyright (C) 2015 |
| 6 | * Lukasz Majewski <l.majewski@majess.pl> |
| 7 | * |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 8 | * Copyright (C) 2012 Samsung Electronics |
| 9 | * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com> |
| 10 | * Lukasz Majewski <l.majewski@samsung.com> |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 14 | #include <command.h> |
Heiko Schocher | 0a9ac5c | 2015-04-14 09:53:13 +0200 | [diff] [blame] | 15 | #include <watchdog.h> |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 16 | #include <dfu.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 17 | #include <console.h> |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 18 | #include <g_dnl.h> |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 19 | #include <usb.h> |
Lukasz Majewski | c2c146f | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 20 | #include <net.h> |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 21 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 22 | static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 23 | { |
Lukasz Majewski | 1cc03c5 | 2014-08-25 11:07:28 +0200 | [diff] [blame] | 24 | |
Patrick Delaunay | febabe3 | 2019-10-14 09:28:02 +0200 | [diff] [blame] | 25 | if (argc < 2) |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 26 | return CMD_RET_USAGE; |
| 27 | |
Marek Vasut | bb4059a | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 28 | #ifdef CONFIG_DFU_OVER_USB |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 29 | char *usb_controller = argv[1]; |
Marek Vasut | 0f44d33 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 30 | #endif |
Andy Shevchenko | cbc1081 | 2019-03-04 16:04:44 +0200 | [diff] [blame] | 31 | #if defined(CONFIG_DFU_OVER_USB) || defined(CONFIG_DFU_OVER_TFTP) |
Patrick Delaunay | febabe3 | 2019-10-14 09:28:02 +0200 | [diff] [blame] | 32 | char *interface = NULL; |
| 33 | char *devstring = NULL; |
Andy Shevchenko | 98a8f44 | 2019-11-27 18:12:15 +0200 | [diff] [blame] | 34 | #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP) |
Andy Shevchenko | 2b1f8c2 | 2019-11-27 18:12:14 +0200 | [diff] [blame] | 35 | unsigned long value = 0; |
| 36 | #endif |
Patrick Delaunay | febabe3 | 2019-10-14 09:28:02 +0200 | [diff] [blame] | 37 | |
| 38 | if (argc >= 4) { |
| 39 | interface = argv[2]; |
| 40 | devstring = argv[3]; |
| 41 | } |
Andy Shevchenko | 2b1f8c2 | 2019-11-27 18:12:14 +0200 | [diff] [blame] | 42 | |
Andy Shevchenko | 98a8f44 | 2019-11-27 18:12:15 +0200 | [diff] [blame] | 43 | #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP) |
Andy Shevchenko | 2b1f8c2 | 2019-11-27 18:12:14 +0200 | [diff] [blame] | 44 | if (argc == 5 || argc == 3) |
| 45 | value = simple_strtoul(argv[argc - 1], NULL, 0); |
| 46 | #endif |
Andy Shevchenko | cbc1081 | 2019-03-04 16:04:44 +0200 | [diff] [blame] | 47 | #endif |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 48 | |
Marek Vasut | 0f44d33 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 49 | int ret = 0; |
Marek Vasut | bb4059a | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 50 | #ifdef CONFIG_DFU_OVER_TFTP |
Andy Shevchenko | 2b1f8c2 | 2019-11-27 18:12:14 +0200 | [diff] [blame] | 51 | if (!strcmp(argv[1], "tftp")) |
| 52 | return update_tftp(value, interface, devstring); |
Lukasz Majewski | c2c146f | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 53 | #endif |
Marek Vasut | bb4059a | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 54 | #ifdef CONFIG_DFU_OVER_USB |
Stephen Warren | dd64827 | 2014-06-11 16:03:33 -0600 | [diff] [blame] | 55 | ret = dfu_init_env_entities(interface, devstring); |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 56 | if (ret) |
Stephen Warren | afb8e71 | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 57 | goto done; |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 58 | |
Andy Shevchenko | 98a8f44 | 2019-11-27 18:12:15 +0200 | [diff] [blame] | 59 | #ifdef CONFIG_DFU_TIMEOUT |
| 60 | dfu_set_timeout(value * 1000); |
| 61 | #endif |
| 62 | |
Stephen Warren | afb8e71 | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 63 | ret = CMD_RET_SUCCESS; |
Patrick Delaunay | febabe3 | 2019-10-14 09:28:02 +0200 | [diff] [blame] | 64 | if (strcmp(argv[argc - 1], "list") == 0) { |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 65 | dfu_show_entities(); |
| 66 | goto done; |
| 67 | } |
| 68 | |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 69 | int controller_index = simple_strtoul(usb_controller, NULL, 0); |
Lukasz Majewski | 1cc03c5 | 2014-08-25 11:07:28 +0200 | [diff] [blame] | 70 | |
B, Ravi | 05341a8 | 2016-07-28 17:39:15 +0530 | [diff] [blame] | 71 | run_usb_dnl_gadget(controller_index, "usb_dnl_dfu"); |
Lukasz Majewski | 6bed7ce | 2013-07-18 13:19:14 +0200 | [diff] [blame] | 72 | |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 73 | done: |
| 74 | dfu_free_entities(); |
Marek Vasut | 0f44d33 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 75 | #endif |
Stephen Warren | afb8e71 | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 76 | return ret; |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu, |
| 80 | "Device Firmware Upgrade", |
Andy Shevchenko | cbc1081 | 2019-03-04 16:04:44 +0200 | [diff] [blame] | 81 | "" |
Marek Vasut | bb4059a | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 82 | #ifdef CONFIG_DFU_OVER_USB |
Andy Shevchenko | 98a8f44 | 2019-11-27 18:12:15 +0200 | [diff] [blame] | 83 | #ifdef CONFIG_DFU_TIMEOUT |
| 84 | "<USB_controller> [<interface> <dev>] [<timeout>] [list]\n" |
| 85 | #else |
Patrick Delaunay | febabe3 | 2019-10-14 09:28:02 +0200 | [diff] [blame] | 86 | "<USB_controller> [<interface> <dev>] [list]\n" |
Andy Shevchenko | 98a8f44 | 2019-11-27 18:12:15 +0200 | [diff] [blame] | 87 | #endif |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 88 | " - device firmware upgrade via <USB_controller>\n" |
| 89 | " on device <dev>, attached to interface\n" |
| 90 | " <interface>\n" |
Andy Shevchenko | 98a8f44 | 2019-11-27 18:12:15 +0200 | [diff] [blame] | 91 | #ifdef CONFIG_DFU_TIMEOUT |
| 92 | " [<timeout>] - specify inactivity timeout in seconds\n" |
| 93 | #endif |
Mateusz Zalega | 16297cf | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 94 | " [list] - list available alt settings\n" |
Marek Vasut | 0f44d33 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 95 | #endif |
Marek Vasut | bb4059a | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 96 | #ifdef CONFIG_DFU_OVER_TFTP |
| 97 | #ifdef CONFIG_DFU_OVER_USB |
Marek Vasut | 0f44d33 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 98 | "dfu " |
| 99 | #endif |
Patrick Delaunay | febabe3 | 2019-10-14 09:28:02 +0200 | [diff] [blame] | 100 | "tftp [<interface> <dev>] [<addr>]\n" |
Lukasz Majewski | c2c146f | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 101 | " - device firmware upgrade via TFTP\n" |
| 102 | " on device <dev>, attached to interface\n" |
| 103 | " <interface>\n" |
| 104 | " [<addr>] - address where FIT image has been stored\n" |
| 105 | #endif |
Lukasz Majewski | a006a5d | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 106 | ); |