Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 2 | /* |
| 3 | * cmd_dfu.c -- dfu command |
| 4 | * |
Lukasz Majewski | 1747a54 | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 5 | * Copyright (C) 2015 |
| 6 | * Lukasz Majewski <l.majewski@majess.pl> |
| 7 | * |
Lukasz Majewski | 9273f4f | 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 | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 11 | */ |
| 12 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 13 | #include <command.h> |
Heiko Schocher | c884884 | 2015-04-14 09:53:13 +0200 | [diff] [blame] | 14 | #include <watchdog.h> |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 15 | #include <dfu.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 16 | #include <console.h> |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 17 | #include <g_dnl.h> |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 18 | #include <usb.h> |
Lukasz Majewski | 1747a54 | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 19 | #include <net.h> |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 20 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 21 | static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 22 | { |
Lukasz Majewski | d9eae70 | 2014-08-25 11:07:28 +0200 | [diff] [blame] | 23 | |
Patrick Delaunay | 0616403 | 2019-10-14 09:28:02 +0200 | [diff] [blame] | 24 | if (argc < 2) |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 25 | return CMD_RET_USAGE; |
| 26 | |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 27 | #ifdef CONFIG_DFU_OVER_USB |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 28 | char *usb_controller = argv[1]; |
Marek Vasut | ea84f80 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 29 | #endif |
Patrick Delaunay | 0616403 | 2019-10-14 09:28:02 +0200 | [diff] [blame] | 30 | char *interface = NULL; |
| 31 | char *devstring = NULL; |
Andy Shevchenko | 1e41401 | 2019-11-27 18:12:15 +0200 | [diff] [blame] | 32 | #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP) |
Andy Shevchenko | 9bb63ec | 2019-11-27 18:12:14 +0200 | [diff] [blame] | 33 | unsigned long value = 0; |
| 34 | #endif |
Patrick Delaunay | 0616403 | 2019-10-14 09:28:02 +0200 | [diff] [blame] | 35 | if (argc >= 4) { |
| 36 | interface = argv[2]; |
| 37 | devstring = argv[3]; |
| 38 | } |
Andy Shevchenko | 9bb63ec | 2019-11-27 18:12:14 +0200 | [diff] [blame] | 39 | |
Andy Shevchenko | 1e41401 | 2019-11-27 18:12:15 +0200 | [diff] [blame] | 40 | #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP) |
Andy Shevchenko | 9bb63ec | 2019-11-27 18:12:14 +0200 | [diff] [blame] | 41 | if (argc == 5 || argc == 3) |
| 42 | value = simple_strtoul(argv[argc - 1], NULL, 0); |
| 43 | #endif |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 44 | |
Marek Vasut | ea84f80 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 45 | int ret = 0; |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 46 | #ifdef CONFIG_DFU_OVER_TFTP |
Andy Shevchenko | 9bb63ec | 2019-11-27 18:12:14 +0200 | [diff] [blame] | 47 | if (!strcmp(argv[1], "tftp")) |
| 48 | return update_tftp(value, interface, devstring); |
Lukasz Majewski | 1747a54 | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 49 | #endif |
Stephen Warren | 4afe50f | 2014-06-11 16:03:33 -0600 | [diff] [blame] | 50 | ret = dfu_init_env_entities(interface, devstring); |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 51 | if (ret) |
Stephen Warren | f9d47dd | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 52 | goto done; |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 53 | |
Andy Shevchenko | 1e41401 | 2019-11-27 18:12:15 +0200 | [diff] [blame] | 54 | #ifdef CONFIG_DFU_TIMEOUT |
| 55 | dfu_set_timeout(value * 1000); |
| 56 | #endif |
| 57 | |
Stephen Warren | f9d47dd | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 58 | ret = CMD_RET_SUCCESS; |
Patrick Delaunay | 0616403 | 2019-10-14 09:28:02 +0200 | [diff] [blame] | 59 | if (strcmp(argv[argc - 1], "list") == 0) { |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 60 | dfu_show_entities(); |
| 61 | goto done; |
| 62 | } |
| 63 | |
Masami Hiramatsu | f77f6a8 | 2022-01-31 11:52:54 +0900 | [diff] [blame] | 64 | #ifdef CONFIG_DFU_OVER_USB |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 65 | int controller_index = simple_strtoul(usb_controller, NULL, 0); |
Marek Szyprowski | f5af8e4 | 2020-12-22 11:32:23 +0100 | [diff] [blame] | 66 | bool retry = false; |
| 67 | do { |
Michal Simek | e13fa3e | 2021-03-31 09:05:52 +0200 | [diff] [blame] | 68 | ret = run_usb_dnl_gadget(controller_index, "usb_dnl_dfu"); |
Lukasz Majewski | d9eae70 | 2014-08-25 11:07:28 +0200 | [diff] [blame] | 69 | |
Marek Szyprowski | f5af8e4 | 2020-12-22 11:32:23 +0100 | [diff] [blame] | 70 | if (dfu_reinit_needed) { |
| 71 | dfu_free_entities(); |
| 72 | ret = dfu_init_env_entities(interface, devstring); |
| 73 | if (ret) |
| 74 | goto done; |
| 75 | retry = true; |
| 76 | } |
| 77 | } while (retry); |
Lukasz Majewski | 2968aa2 | 2013-07-18 13:19:14 +0200 | [diff] [blame] | 78 | |
Masami Hiramatsu | f77f6a8 | 2022-01-31 11:52:54 +0900 | [diff] [blame] | 79 | #endif |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 80 | done: |
| 81 | dfu_free_entities(); |
Stephen Warren | f9d47dd | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 82 | return ret; |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu, |
| 86 | "Device Firmware Upgrade", |
Andy Shevchenko | 1cfb956 | 2019-03-04 16:04:44 +0200 | [diff] [blame] | 87 | "" |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 88 | #ifdef CONFIG_DFU_OVER_USB |
Andy Shevchenko | 1e41401 | 2019-11-27 18:12:15 +0200 | [diff] [blame] | 89 | #ifdef CONFIG_DFU_TIMEOUT |
| 90 | "<USB_controller> [<interface> <dev>] [<timeout>] [list]\n" |
| 91 | #else |
Patrick Delaunay | 0616403 | 2019-10-14 09:28:02 +0200 | [diff] [blame] | 92 | "<USB_controller> [<interface> <dev>] [list]\n" |
Andy Shevchenko | 1e41401 | 2019-11-27 18:12:15 +0200 | [diff] [blame] | 93 | #endif |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 94 | " - device firmware upgrade via <USB_controller>\n" |
| 95 | " on device <dev>, attached to interface\n" |
| 96 | " <interface>\n" |
Andy Shevchenko | 1e41401 | 2019-11-27 18:12:15 +0200 | [diff] [blame] | 97 | #ifdef CONFIG_DFU_TIMEOUT |
| 98 | " [<timeout>] - specify inactivity timeout in seconds\n" |
| 99 | #endif |
Marek Vasut | ea84f80 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 100 | #endif |
Masami Hiramatsu | f77f6a8 | 2022-01-31 11:52:54 +0900 | [diff] [blame] | 101 | " [list] - list available alt settings\n" |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 102 | #ifdef CONFIG_DFU_OVER_TFTP |
| 103 | #ifdef CONFIG_DFU_OVER_USB |
Marek Vasut | ea84f80 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 104 | "dfu " |
| 105 | #endif |
Patrick Delaunay | 0616403 | 2019-10-14 09:28:02 +0200 | [diff] [blame] | 106 | "tftp [<interface> <dev>] [<addr>]\n" |
Lukasz Majewski | 1747a54 | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 107 | " - device firmware upgrade via TFTP\n" |
| 108 | " on device <dev>, attached to interface\n" |
| 109 | " <interface>\n" |
| 110 | " [<addr>] - address where FIT image has been stored\n" |
| 111 | #endif |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 112 | ); |