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 | |
| 13 | #include <common.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 | |
| 21 | static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 22 | { |
Lukasz Majewski | d9eae70 | 2014-08-25 11:07:28 +0200 | [diff] [blame] | 23 | |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 24 | if (argc < 4) |
| 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 |
Andy Shevchenko | 1cfb956 | 2019-03-04 16:04:44 +0200 | [diff] [blame] | 30 | #if defined(CONFIG_DFU_OVER_USB) || defined(CONFIG_DFU_OVER_TFTP) |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 31 | char *interface = argv[2]; |
| 32 | char *devstring = argv[3]; |
Andy Shevchenko | 1cfb956 | 2019-03-04 16:04:44 +0200 | [diff] [blame] | 33 | #endif |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 34 | |
Marek Vasut | ea84f80 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 35 | int ret = 0; |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 36 | #ifdef CONFIG_DFU_OVER_TFTP |
Lukasz Majewski | 1747a54 | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 37 | unsigned long addr = 0; |
| 38 | if (!strcmp(argv[1], "tftp")) { |
| 39 | if (argc == 5) |
| 40 | addr = simple_strtoul(argv[4], NULL, 0); |
| 41 | |
| 42 | return update_tftp(addr, interface, devstring); |
| 43 | } |
| 44 | #endif |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 45 | #ifdef CONFIG_DFU_OVER_USB |
Stephen Warren | 4afe50f | 2014-06-11 16:03:33 -0600 | [diff] [blame] | 46 | ret = dfu_init_env_entities(interface, devstring); |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 47 | if (ret) |
Stephen Warren | f9d47dd | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 48 | goto done; |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 49 | |
Stephen Warren | f9d47dd | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 50 | ret = CMD_RET_SUCCESS; |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 51 | if (argc > 4 && strcmp(argv[4], "list") == 0) { |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 52 | dfu_show_entities(); |
| 53 | goto done; |
| 54 | } |
| 55 | |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 56 | int controller_index = simple_strtoul(usb_controller, NULL, 0); |
Lukasz Majewski | d9eae70 | 2014-08-25 11:07:28 +0200 | [diff] [blame] | 57 | |
B, Ravi | 603a4c1 | 2016-07-28 17:39:15 +0530 | [diff] [blame] | 58 | run_usb_dnl_gadget(controller_index, "usb_dnl_dfu"); |
Lukasz Majewski | 2968aa2 | 2013-07-18 13:19:14 +0200 | [diff] [blame] | 59 | |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 60 | done: |
| 61 | dfu_free_entities(); |
Marek Vasut | ea84f80 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 62 | #endif |
Stephen Warren | f9d47dd | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 63 | return ret; |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu, |
| 67 | "Device Firmware Upgrade", |
Andy Shevchenko | 1cfb956 | 2019-03-04 16:04:44 +0200 | [diff] [blame] | 68 | "" |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 69 | #ifdef CONFIG_DFU_OVER_USB |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 70 | "<USB_controller> <interface> <dev> [list]\n" |
| 71 | " - device firmware upgrade via <USB_controller>\n" |
| 72 | " on device <dev>, attached to interface\n" |
| 73 | " <interface>\n" |
| 74 | " [list] - list available alt settings\n" |
Marek Vasut | ea84f80 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 75 | #endif |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 76 | #ifdef CONFIG_DFU_OVER_TFTP |
| 77 | #ifdef CONFIG_DFU_OVER_USB |
Marek Vasut | ea84f80 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 78 | "dfu " |
| 79 | #endif |
| 80 | "tftp <interface> <dev> [<addr>]\n" |
Lukasz Majewski | 1747a54 | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 81 | " - device firmware upgrade via TFTP\n" |
| 82 | " on device <dev>, attached to interface\n" |
| 83 | " <interface>\n" |
| 84 | " [<addr>] - address where FIT image has been stored\n" |
| 85 | #endif |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 86 | ); |