]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
a006a5de ŁM |
2 | /* |
3 | * cmd_dfu.c -- dfu command | |
4 | * | |
c2c146fb LM |
5 | * Copyright (C) 2015 |
6 | * Lukasz Majewski <[email protected]> | |
7 | * | |
a006a5de ŁM |
8 | * Copyright (C) 2012 Samsung Electronics |
9 | * authors: Andrzej Pietrasiewicz <[email protected]> | |
10 | * Lukasz Majewski <[email protected]> | |
a006a5de ŁM |
11 | */ |
12 | ||
13 | #include <common.h> | |
09140113 | 14 | #include <command.h> |
0a9ac5cb | 15 | #include <watchdog.h> |
a006a5de | 16 | #include <dfu.h> |
24b852a7 | 17 | #include <console.h> |
a006a5de | 18 | #include <g_dnl.h> |
16297cfb | 19 | #include <usb.h> |
c2c146fb | 20 | #include <net.h> |
a006a5de | 21 | |
09140113 | 22 | static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
a006a5de | 23 | { |
1cc03c5c | 24 | |
febabe3e | 25 | if (argc < 2) |
16297cfb MZ |
26 | return CMD_RET_USAGE; |
27 | ||
bb4059a5 | 28 | #ifdef CONFIG_DFU_OVER_USB |
16297cfb | 29 | char *usb_controller = argv[1]; |
0f44d335 | 30 | #endif |
cbc1081d | 31 | #if defined(CONFIG_DFU_OVER_USB) || defined(CONFIG_DFU_OVER_TFTP) |
febabe3e PD |
32 | char *interface = NULL; |
33 | char *devstring = NULL; | |
98a8f445 | 34 | #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP) |
2b1f8c2b AS |
35 | unsigned long value = 0; |
36 | #endif | |
febabe3e PD |
37 | |
38 | if (argc >= 4) { | |
39 | interface = argv[2]; | |
40 | devstring = argv[3]; | |
41 | } | |
2b1f8c2b | 42 | |
98a8f445 | 43 | #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP) |
2b1f8c2b AS |
44 | if (argc == 5 || argc == 3) |
45 | value = simple_strtoul(argv[argc - 1], NULL, 0); | |
46 | #endif | |
cbc1081d | 47 | #endif |
16297cfb | 48 | |
0f44d335 | 49 | int ret = 0; |
bb4059a5 | 50 | #ifdef CONFIG_DFU_OVER_TFTP |
2b1f8c2b AS |
51 | if (!strcmp(argv[1], "tftp")) |
52 | return update_tftp(value, interface, devstring); | |
c2c146fb | 53 | #endif |
bb4059a5 | 54 | #ifdef CONFIG_DFU_OVER_USB |
dd64827e | 55 | ret = dfu_init_env_entities(interface, devstring); |
a006a5de | 56 | if (ret) |
afb8e71c | 57 | goto done; |
a006a5de | 58 | |
98a8f445 AS |
59 | #ifdef CONFIG_DFU_TIMEOUT |
60 | dfu_set_timeout(value * 1000); | |
61 | #endif | |
62 | ||
afb8e71c | 63 | ret = CMD_RET_SUCCESS; |
febabe3e | 64 | if (strcmp(argv[argc - 1], "list") == 0) { |
a006a5de ŁM |
65 | dfu_show_entities(); |
66 | goto done; | |
67 | } | |
68 | ||
16297cfb | 69 | int controller_index = simple_strtoul(usb_controller, NULL, 0); |
1cc03c5c | 70 | |
05341a87 | 71 | run_usb_dnl_gadget(controller_index, "usb_dnl_dfu"); |
6bed7ce5 | 72 | |
a006a5de ŁM |
73 | done: |
74 | dfu_free_entities(); | |
0f44d335 | 75 | #endif |
afb8e71c | 76 | return ret; |
a006a5de ŁM |
77 | } |
78 | ||
79 | U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu, | |
80 | "Device Firmware Upgrade", | |
cbc1081d | 81 | "" |
bb4059a5 | 82 | #ifdef CONFIG_DFU_OVER_USB |
98a8f445 AS |
83 | #ifdef CONFIG_DFU_TIMEOUT |
84 | "<USB_controller> [<interface> <dev>] [<timeout>] [list]\n" | |
85 | #else | |
febabe3e | 86 | "<USB_controller> [<interface> <dev>] [list]\n" |
98a8f445 | 87 | #endif |
16297cfb MZ |
88 | " - device firmware upgrade via <USB_controller>\n" |
89 | " on device <dev>, attached to interface\n" | |
90 | " <interface>\n" | |
98a8f445 AS |
91 | #ifdef CONFIG_DFU_TIMEOUT |
92 | " [<timeout>] - specify inactivity timeout in seconds\n" | |
93 | #endif | |
16297cfb | 94 | " [list] - list available alt settings\n" |
0f44d335 | 95 | #endif |
bb4059a5 MV |
96 | #ifdef CONFIG_DFU_OVER_TFTP |
97 | #ifdef CONFIG_DFU_OVER_USB | |
0f44d335 MV |
98 | "dfu " |
99 | #endif | |
febabe3e | 100 | "tftp [<interface> <dev>] [<addr>]\n" |
c2c146fb LM |
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 | |
a006a5de | 106 | ); |