]>
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 | ||
09140113 | 13 | #include <command.h> |
0a9ac5cb | 14 | #include <watchdog.h> |
a006a5de | 15 | #include <dfu.h> |
24b852a7 | 16 | #include <console.h> |
a006a5de | 17 | #include <g_dnl.h> |
16297cfb | 18 | #include <usb.h> |
c2c146fb | 19 | #include <net.h> |
a006a5de | 20 | |
09140113 | 21 | static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
a006a5de | 22 | { |
1cc03c5c | 23 | |
febabe3e | 24 | if (argc < 2) |
16297cfb MZ |
25 | return CMD_RET_USAGE; |
26 | ||
bb4059a5 | 27 | #ifdef CONFIG_DFU_OVER_USB |
16297cfb | 28 | char *usb_controller = argv[1]; |
0f44d335 | 29 | #endif |
febabe3e PD |
30 | char *interface = NULL; |
31 | char *devstring = NULL; | |
98a8f445 | 32 | #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP) |
2b1f8c2b AS |
33 | unsigned long value = 0; |
34 | #endif | |
febabe3e PD |
35 | if (argc >= 4) { |
36 | interface = argv[2]; | |
37 | devstring = argv[3]; | |
38 | } | |
2b1f8c2b | 39 | |
98a8f445 | 40 | #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP) |
2b1f8c2b AS |
41 | if (argc == 5 || argc == 3) |
42 | value = simple_strtoul(argv[argc - 1], NULL, 0); | |
cbc1081d | 43 | #endif |
16297cfb | 44 | |
0f44d335 | 45 | int ret = 0; |
bb4059a5 | 46 | #ifdef CONFIG_DFU_OVER_TFTP |
2b1f8c2b AS |
47 | if (!strcmp(argv[1], "tftp")) |
48 | return update_tftp(value, interface, devstring); | |
c2c146fb | 49 | #endif |
dd64827e | 50 | ret = dfu_init_env_entities(interface, devstring); |
a006a5de | 51 | if (ret) |
afb8e71c | 52 | goto done; |
a006a5de | 53 | |
98a8f445 AS |
54 | #ifdef CONFIG_DFU_TIMEOUT |
55 | dfu_set_timeout(value * 1000); | |
56 | #endif | |
57 | ||
afb8e71c | 58 | ret = CMD_RET_SUCCESS; |
febabe3e | 59 | if (strcmp(argv[argc - 1], "list") == 0) { |
a006a5de ŁM |
60 | dfu_show_entities(); |
61 | goto done; | |
62 | } | |
63 | ||
e9b0fd83 | 64 | #ifdef CONFIG_DFU_OVER_USB |
16297cfb | 65 | int controller_index = simple_strtoul(usb_controller, NULL, 0); |
9129f2f1 MS |
66 | bool retry = false; |
67 | do { | |
74fe3f2e | 68 | ret = run_usb_dnl_gadget(controller_index, "usb_dnl_dfu"); |
1cc03c5c | 69 | |
9129f2f1 MS |
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); | |
6bed7ce5 | 78 | |
e9b0fd83 | 79 | #endif |
a006a5de ŁM |
80 | done: |
81 | dfu_free_entities(); | |
afb8e71c | 82 | return ret; |
a006a5de ŁM |
83 | } |
84 | ||
85 | U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu, | |
86 | "Device Firmware Upgrade", | |
cbc1081d | 87 | "" |
bb4059a5 | 88 | #ifdef CONFIG_DFU_OVER_USB |
98a8f445 AS |
89 | #ifdef CONFIG_DFU_TIMEOUT |
90 | "<USB_controller> [<interface> <dev>] [<timeout>] [list]\n" | |
91 | #else | |
febabe3e | 92 | "<USB_controller> [<interface> <dev>] [list]\n" |
98a8f445 | 93 | #endif |
16297cfb MZ |
94 | " - device firmware upgrade via <USB_controller>\n" |
95 | " on device <dev>, attached to interface\n" | |
96 | " <interface>\n" | |
98a8f445 AS |
97 | #ifdef CONFIG_DFU_TIMEOUT |
98 | " [<timeout>] - specify inactivity timeout in seconds\n" | |
99 | #endif | |
0f44d335 | 100 | #endif |
e9b0fd83 | 101 | " [list] - list available alt settings\n" |
bb4059a5 MV |
102 | #ifdef CONFIG_DFU_OVER_TFTP |
103 | #ifdef CONFIG_DFU_OVER_USB | |
0f44d335 MV |
104 | "dfu " |
105 | #endif | |
febabe3e | 106 | "tftp [<interface> <dev>] [<addr>]\n" |
c2c146fb LM |
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 | |
a006a5de | 112 | ); |