Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 1 | /* |
| 2 | * cmd_dfu.c -- dfu command |
| 3 | * |
Lukasz Majewski | 1747a54 | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 4 | * Copyright (C) 2015 |
| 5 | * Lukasz Majewski <l.majewski@majess.pl> |
| 6 | * |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 7 | * Copyright (C) 2012 Samsung Electronics |
| 8 | * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com> |
| 9 | * Lukasz Majewski <l.majewski@samsung.com> |
| 10 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 11 | * SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
Heiko Schocher | c884884 | 2015-04-14 09:53:13 +0200 | [diff] [blame] | 15 | #include <watchdog.h> |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 16 | #include <dfu.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 17 | #include <console.h> |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 18 | #include <g_dnl.h> |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 19 | #include <usb.h> |
Lukasz Majewski | 1747a54 | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 20 | #include <net.h> |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 21 | |
| 22 | static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| 23 | { |
Lukasz Majewski | d9eae70 | 2014-08-25 11:07:28 +0200 | [diff] [blame] | 24 | |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 25 | if (argc < 4) |
| 26 | return CMD_RET_USAGE; |
| 27 | |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 28 | #ifdef CONFIG_DFU_OVER_USB |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 29 | char *usb_controller = argv[1]; |
Marek Vasut | ea84f80 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 30 | #endif |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 31 | char *interface = argv[2]; |
| 32 | char *devstring = argv[3]; |
| 33 | |
Marek Vasut | ea84f80 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 34 | int ret = 0; |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 35 | #ifdef CONFIG_DFU_OVER_TFTP |
Lukasz Majewski | 1747a54 | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 36 | unsigned long addr = 0; |
| 37 | if (!strcmp(argv[1], "tftp")) { |
| 38 | if (argc == 5) |
| 39 | addr = simple_strtoul(argv[4], NULL, 0); |
| 40 | |
| 41 | return update_tftp(addr, interface, devstring); |
| 42 | } |
| 43 | #endif |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 44 | #ifdef CONFIG_DFU_OVER_USB |
Stephen Warren | 4afe50f | 2014-06-11 16:03:33 -0600 | [diff] [blame] | 45 | ret = dfu_init_env_entities(interface, devstring); |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 46 | if (ret) |
Stephen Warren | f9d47dd | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 47 | goto done; |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 48 | |
Stephen Warren | f9d47dd | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 49 | ret = CMD_RET_SUCCESS; |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 50 | if (argc > 4 && strcmp(argv[4], "list") == 0) { |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 51 | dfu_show_entities(); |
| 52 | goto done; |
| 53 | } |
| 54 | |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 55 | int controller_index = simple_strtoul(usb_controller, NULL, 0); |
Lukasz Majewski | d9eae70 | 2014-08-25 11:07:28 +0200 | [diff] [blame] | 56 | |
B, Ravi | 603a4c1 | 2016-07-28 17:39:15 +0530 | [diff] [blame] | 57 | run_usb_dnl_gadget(controller_index, "usb_dnl_dfu"); |
Lukasz Majewski | 2968aa2 | 2013-07-18 13:19:14 +0200 | [diff] [blame] | 58 | |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 59 | done: |
| 60 | dfu_free_entities(); |
Marek Vasut | ea84f80 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 61 | #endif |
Stephen Warren | f9d47dd | 2014-06-10 10:06:41 -0600 | [diff] [blame] | 62 | return ret; |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu, |
| 66 | "Device Firmware Upgrade", |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 67 | #ifdef CONFIG_DFU_OVER_USB |
Mateusz Zalega | d862f89 | 2013-10-04 19:22:26 +0200 | [diff] [blame] | 68 | "<USB_controller> <interface> <dev> [list]\n" |
| 69 | " - device firmware upgrade via <USB_controller>\n" |
| 70 | " on device <dev>, attached to interface\n" |
| 71 | " <interface>\n" |
| 72 | " [list] - list available alt settings\n" |
Marek Vasut | ea84f80 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 73 | #endif |
Marek Vasut | 7f8d436 | 2018-02-16 16:41:18 +0100 | [diff] [blame] | 74 | #ifdef CONFIG_DFU_OVER_TFTP |
| 75 | #ifdef CONFIG_DFU_OVER_USB |
Marek Vasut | ea84f80 | 2018-02-16 16:41:17 +0100 | [diff] [blame] | 76 | "dfu " |
| 77 | #endif |
| 78 | "tftp <interface> <dev> [<addr>]\n" |
Lukasz Majewski | 1747a54 | 2015-08-24 00:21:48 +0200 | [diff] [blame] | 79 | " - device firmware upgrade via TFTP\n" |
| 80 | " on device <dev>, attached to interface\n" |
| 81 | " <interface>\n" |
| 82 | " [<addr>] - address where FIT image has been stored\n" |
| 83 | #endif |
Lukasz Majewski | 9273f4f | 2012-08-06 14:41:09 +0200 | [diff] [blame] | 84 | ); |