samsung: tizen_amlogic: increase ramdisk size from 8M to 32M
[platform/kernel/u-boot.git] / cmd / dfu.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * cmd_dfu.c -- dfu command
4  *
5  * Copyright (C) 2015
6  * Lukasz Majewski <l.majewski@majess.pl>
7  *
8  * Copyright (C) 2012 Samsung Electronics
9  * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
10  *          Lukasz Majewski <l.majewski@samsung.com>
11  */
12
13 #include <common.h>
14 #include <command.h>
15 #include <watchdog.h>
16 #include <dfu.h>
17 #include <console.h>
18 #include <g_dnl.h>
19 #include <usb.h>
20 #include <net.h>
21
22 static int do_dfu(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
23 {
24 #ifndef CONFIG_DFU_OVER_USB
25         if (argc < 2)
26                 return CMD_RET_USAGE;
27 #endif
28 #ifdef CONFIG_DFU_OVER_USB
29         char *usb_controller = argv[1];
30 #endif
31 #if defined(CONFIG_DFU_OVER_USB) || defined(CONFIG_DFU_OVER_TFTP)
32         char *interface = NULL;
33         char *devstring = NULL;
34 #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
35         unsigned long value = 0;
36 #endif
37         if (argc >= 4) {
38                 interface = argv[2];
39                 devstring = argv[3];
40         }
41
42 #if defined(CONFIG_DFU_TIMEOUT) || defined(CONFIG_DFU_OVER_TFTP)
43         if (argc == 5 || argc == 3)
44                 value = simple_strtoul(argv[argc - 1], NULL, 0);
45 #endif
46 #endif
47
48         int ret = 0;
49
50 #ifdef CONFIG_DFU_OVER_USB
51         int argv_list = 0;
52         bool dfu_reset = false;
53         switch (argc) {
54         case 2:
55                 argv_list = 1;
56         case 1:
57                 usb_controller = strdup(env_get("dfu_usb_con"));
58                 interface = strdup(env_get("dfu_interface"));
59                 devstring = strdup(env_get("dfu_device"));
60                 if (!usb_controller || !interface || !devstring) {
61                         puts("DFU: default device environment is not set.\n");
62                         ret = CMD_RET_USAGE;
63                         goto bad_args;
64                 }
65                 break;
66         case 5:
67                 argv_list = 4;
68         case 4:
69                 usb_controller = argv[1];
70                 interface = argv[2];
71                 devstring = argv[3];
72                 break;
73         default:
74                 return CMD_RET_USAGE;
75         }
76 #endif
77 #ifdef CONFIG_DFU_OVER_TFTP
78         if (!strcmp(argv[1], "tftp"))
79                 return update_tftp(value, interface, devstring);
80 #endif
81 #ifdef CONFIG_DFU_OVER_USB
82         ret = dfu_init_env_entities(interface, devstring);
83         if (ret)
84                 goto done;
85
86 #ifdef CONFIG_DFU_TIMEOUT
87         dfu_set_timeout(value * 1000);
88 #endif
89
90         if (argv_list && !strcmp(argv[argv_list], "list")) {
91                 dfu_show_entities();
92                 goto done;
93         }
94
95         int controller_index = simple_strtoul(usb_controller, NULL, 0);
96         bool retry = false;
97         do {
98                 ret = run_usb_dnl_gadget(controller_index, "usb_dnl_dfu");
99
100                 if (dfu_reinit_needed) {
101                         dfu_free_entities();
102                         ret = dfu_init_env_entities(interface, devstring);
103                         if (ret)
104                                 goto done;
105                         retry = true;
106                 }
107         } while (retry);
108
109 done:
110         dfu_free_entities();
111
112         if (dfu_reset)
113                 run_command("reset", 0);
114
115         g_dnl_clear_detach();
116 bad_args:
117         if (argc == 1) {
118                 free(usb_controller);
119                 free(interface);
120                 free(devstring);
121         }
122 #endif
123         return ret;
124 }
125
126 U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu,
127         "Device Firmware Upgrade",
128         ""
129 #ifdef CONFIG_DFU_OVER_USB
130 #ifdef CONFIG_DFU_TIMEOUT
131         "<USB_controller> [<interface> <dev>] [<timeout>] [list]\n"
132 #else
133         "<USB_controller> [<interface> <dev>] [list]\n"
134 #endif
135         "  - device firmware upgrade via <USB_controller>\n"
136         "    on device <dev>, attached to interface\n"
137         "    <interface>\n"
138 #ifdef CONFIG_DFU_TIMEOUT
139         "    [<timeout>] - specify inactivity timeout in seconds\n"
140 #endif
141         "    [list] - list available alt settings\n"
142 #endif
143 #ifdef CONFIG_DFU_OVER_TFTP
144 #ifdef CONFIG_DFU_OVER_USB
145         "dfu "
146 #endif
147         "tftp [<interface> <dev>] [<addr>]\n"
148         "  - device firmware upgrade via TFTP\n"
149         "    on device <dev>, attached to interface\n"
150         "    <interface>\n"
151         "    [<addr>] - address where FIT image has been stored\n"
152 #endif
153 );