Commit c7ff5528439af8f1e6e10424e495eb7d6238d6c5
Committed by
Marek Vasut
1 parent
2092e46104
Exists in
v2017.01-smarct4x
and in
32 other branches
update: tftp: dfu: Extend update_tftp() function to support DFU
This code allows using DFU defined mediums for storing data received via TFTP protocol. It reuses and preserves functionality of legacy code at common/update.c. The update_tftp() function now accepts parameters - namely medium device name and its number (e.g. mmc 1). Without this information passed old behavior is preserved. Signed-off-by: Lukasz Majewski <l.majewski@majess.pl> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
Showing 5 changed files with 52 additions and 14 deletions Side-by-side Diff
common/Makefile
... | ... | @@ -210,6 +210,7 @@ |
210 | 210 | obj-$(CONFIG_MENU) += menu.o |
211 | 211 | obj-$(CONFIG_MODEM_SUPPORT) += modem.o |
212 | 212 | obj-$(CONFIG_UPDATE_TFTP) += update.o |
213 | +obj-$(CONFIG_DFU_TFTP) += update.o | |
213 | 214 | obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o |
214 | 215 | obj-$(CONFIG_CMD_DFU) += cmd_dfu.o |
215 | 216 | obj-$(CONFIG_CMD_GPT) += cmd_gpt.o |
common/cmd_fitupd.c
common/main.c
common/update.c
... | ... | @@ -13,11 +13,17 @@ |
13 | 13 | #error "CONFIG_FIT and CONFIG_OF_LIBFDT are required for auto-update feature" |
14 | 14 | #endif |
15 | 15 | |
16 | +#if defined(CONFIG_UPDATE_TFTP) && defined(CONFIG_SYS_NO_FLASH) | |
17 | +#error "CONFIG_UPDATE_TFTP and CONFIG_SYS_NO_FLASH needed for legacy behaviour" | |
18 | +#endif | |
19 | + | |
16 | 20 | #include <command.h> |
17 | 21 | #include <flash.h> |
18 | 22 | #include <net.h> |
19 | 23 | #include <net/tftp.h> |
20 | 24 | #include <malloc.h> |
25 | +#include <dfu.h> | |
26 | +#include <errno.h> | |
21 | 27 | |
22 | 28 | /* env variable holding the location of the update file */ |
23 | 29 | #define UPDATE_FILE_ENV "updatefile" |
24 | 30 | |
25 | 31 | |
26 | 32 | |
27 | 33 | |
... | ... | @@ -222,14 +228,25 @@ |
222 | 228 | return 0; |
223 | 229 | } |
224 | 230 | |
225 | -int update_tftp(ulong addr) | |
231 | +int update_tftp(ulong addr, char *interface, char *devstring) | |
226 | 232 | { |
227 | - char *filename, *env_addr; | |
228 | - int images_noffset, ndepth, noffset; | |
233 | + char *filename, *env_addr, *fit_image_name; | |
229 | 234 | ulong update_addr, update_fladdr, update_size; |
230 | - void *fit; | |
235 | + int images_noffset, ndepth, noffset; | |
236 | + bool update_tftp_dfu; | |
231 | 237 | int ret = 0; |
238 | + void *fit; | |
232 | 239 | |
240 | + if (interface == NULL && devstring == NULL) { | |
241 | + update_tftp_dfu = false; | |
242 | + } else if (interface && devstring) { | |
243 | + update_tftp_dfu = true; | |
244 | + } else { | |
245 | + error("Interface: %s and devstring: %s not supported!\n", | |
246 | + interface, devstring); | |
247 | + return -EINVAL; | |
248 | + } | |
249 | + | |
233 | 250 | /* use already present image */ |
234 | 251 | if (addr) |
235 | 252 | goto got_update_file; |
... | ... | @@ -277,8 +294,8 @@ |
277 | 294 | if (ndepth != 1) |
278 | 295 | goto next_node; |
279 | 296 | |
280 | - printf("Processing update '%s' :", | |
281 | - fit_get_name(fit, noffset, NULL)); | |
297 | + fit_image_name = (char *)fit_get_name(fit, noffset, NULL); | |
298 | + printf("Processing update '%s' :", fit_image_name); | |
282 | 299 | |
283 | 300 | if (!fit_image_verify(fit, noffset)) { |
284 | 301 | printf("Error: invalid update hash, aborting\n"); |
... | ... | @@ -294,10 +311,20 @@ |
294 | 311 | ret = 1; |
295 | 312 | goto next_node; |
296 | 313 | } |
297 | - if (update_flash(update_addr, update_fladdr, update_size)) { | |
298 | - printf("Error: can't flash update, aborting\n"); | |
299 | - ret = 1; | |
300 | - goto next_node; | |
314 | + | |
315 | + if (!update_tftp_dfu) { | |
316 | + if (update_flash(update_addr, update_fladdr, | |
317 | + update_size)) { | |
318 | + printf("Error: can't flash update, aborting\n"); | |
319 | + ret = 1; | |
320 | + goto next_node; | |
321 | + } | |
322 | + } else if (fit_image_check_type(fit, noffset, | |
323 | + IH_TYPE_FIRMWARE)) { | |
324 | + ret = dfu_tftp_write(fit_image_name, update_addr, | |
325 | + update_size, interface, devstring); | |
326 | + if (ret) | |
327 | + return ret; | |
301 | 328 | } |
302 | 329 | next_node: |
303 | 330 | noffset = fdt_next_node(fit, noffset, &ndepth); |
include/net.h
... | ... | @@ -813,8 +813,18 @@ |
813 | 813 | /* get a random source port */ |
814 | 814 | unsigned int random_port(void); |
815 | 815 | |
816 | -/* Update U-Boot over TFTP */ | |
817 | -int update_tftp(ulong addr); | |
816 | +/** | |
817 | + * update_tftp - Update firmware over TFTP (via DFU) | |
818 | + * | |
819 | + * This function updates board's firmware via TFTP | |
820 | + * | |
821 | + * @param addr - memory address where data is stored | |
822 | + * @param interface - the DFU medium name - e.g. "mmc" | |
823 | + * @param devstring - the DFU medium number - e.g. "1" | |
824 | + * | |
825 | + * @return - 0 on success, other value on failure | |
826 | + */ | |
827 | +int update_tftp(ulong addr, char *interface, char *devstring); | |
818 | 828 | |
819 | 829 | /**********************************************************************/ |
820 | 830 |