diff options
| author | Tom Rini <trini@konsulko.com> | 2015-09-07 08:56:23 -0400 |
|---|---|---|
| committer | Tom Rini <trini@konsulko.com> | 2015-09-07 08:56:23 -0400 |
| commit | cdc7732f3737f2bb97b77eb3d7c9da344bb73612 (patch) | |
| tree | 5d3a3567a1a58335ed2f38d8228cf24483f79b14 /common | |
| parent | a6003397f7b74f7af6c21954073e046de08f43c9 (diff) | |
| parent | 49b4c5c700077e387fef61a7225f92d190ee0c45 (diff) | |
Merge git://git.denx.de/u-boot-usb
Diffstat (limited to 'common')
| -rw-r--r-- | common/Makefile | 1 | ||||
| -rw-r--r-- | common/cmd_dfu.c | 20 | ||||
| -rw-r--r-- | common/cmd_fitupd.c | 2 | ||||
| -rw-r--r-- | common/main.c | 2 | ||||
| -rw-r--r-- | common/update.c | 58 |
5 files changed, 65 insertions, 18 deletions
diff --git a/common/Makefile b/common/Makefile index f4ba8782f5..556fb07592 100644 --- a/common/Makefile +++ b/common/Makefile @@ -210,6 +210,7 @@ obj-$(CONFIG_LYNXKDI) += lynxkdi.o obj-$(CONFIG_MENU) += menu.o obj-$(CONFIG_MODEM_SUPPORT) += modem.o obj-$(CONFIG_UPDATE_TFTP) += update.o +obj-$(CONFIG_DFU_TFTP) += update.o obj-$(CONFIG_USB_KEYBOARD) += usb_kbd.o obj-$(CONFIG_CMD_DFU) += cmd_dfu.o obj-$(CONFIG_CMD_GPT) += cmd_gpt.o diff --git a/common/cmd_dfu.c b/common/cmd_dfu.c index 857148f8af..f060db75c6 100644 --- a/common/cmd_dfu.c +++ b/common/cmd_dfu.c @@ -1,6 +1,9 @@ /* * cmd_dfu.c -- dfu command * + * Copyright (C) 2015 + * Lukasz Majewski <l.majewski@majess.pl> + * * Copyright (C) 2012 Samsung Electronics * authors: Andrzej Pietrasiewicz <andrzej.p@samsung.com> * Lukasz Majewski <l.majewski@samsung.com> @@ -13,6 +16,7 @@ #include <dfu.h> #include <g_dnl.h> #include <usb.h> +#include <net.h> static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -26,6 +30,15 @@ static int do_dfu(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char *devstring = argv[3]; int ret, i = 0; +#ifdef CONFIG_DFU_TFTP + unsigned long addr = 0; + if (!strcmp(argv[1], "tftp")) { + if (argc == 5) + addr = simple_strtoul(argv[4], NULL, 0); + + return update_tftp(addr, interface, devstring); + } +#endif ret = dfu_init_env_entities(interface, devstring); if (ret) @@ -89,4 +102,11 @@ U_BOOT_CMD(dfu, CONFIG_SYS_MAXARGS, 1, do_dfu, " on device <dev>, attached to interface\n" " <interface>\n" " [list] - list available alt settings\n" +#ifdef CONFIG_DFU_TFTP + "dfu tftp <interface> <dev> [<addr>]\n" + " - device firmware upgrade via TFTP\n" + " on device <dev>, attached to interface\n" + " <interface>\n" + " [<addr>] - address where FIT image has been stored\n" +#endif ); diff --git a/common/cmd_fitupd.c b/common/cmd_fitupd.c index b0459744d9..78b8747336 100644 --- a/common/cmd_fitupd.c +++ b/common/cmd_fitupd.c @@ -23,7 +23,7 @@ static int do_fitupd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (argc == 2) addr = simple_strtoul(argv[1], NULL, 16); - return update_tftp(addr); + return update_tftp(addr, NULL, NULL); } U_BOOT_CMD(fitupd, 2, 0, do_fitupd, diff --git a/common/main.c b/common/main.c index 2979fbed63..ead0cd17aa 100644 --- a/common/main.c +++ b/common/main.c @@ -75,7 +75,7 @@ void main_loop(void) run_preboot_environment_command(); #if defined(CONFIG_UPDATE_TFTP) - update_tftp(0UL); + update_tftp(0UL, NULL, NULL); #endif /* CONFIG_UPDATE_TFTP */ s = bootdelay_process(); diff --git a/common/update.c b/common/update.c index 1c6aa186d0..1da80b70f2 100644 --- a/common/update.c +++ b/common/update.c @@ -13,8 +13,8 @@ #error "CONFIG_FIT and CONFIG_OF_LIBFDT are required for auto-update feature" #endif -#if defined(CONFIG_SYS_NO_FLASH) -#error "CONFIG_SYS_NO_FLASH defined, but FLASH is required for auto-update feature" +#if defined(CONFIG_UPDATE_TFTP) && defined(CONFIG_SYS_NO_FLASH) +#error "CONFIG_UPDATE_TFTP and CONFIG_SYS_NO_FLASH needed for legacy behaviour" #endif #include <command.h> @@ -22,6 +22,8 @@ #include <net.h> #include <net/tftp.h> #include <malloc.h> +#include <dfu.h> +#include <errno.h> /* env variable holding the location of the update file */ #define UPDATE_FILE_ENV "updatefile" @@ -41,11 +43,11 @@ extern ulong tftp_timeout_ms; extern int tftp_timeout_count_max; -extern flash_info_t flash_info[]; extern ulong load_addr; - +#ifndef CONFIG_SYS_NO_FLASH +extern flash_info_t flash_info[]; static uchar *saved_prot_info; - +#endif static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr) { int size, rv; @@ -94,6 +96,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr) return rv; } +#ifndef CONFIG_SYS_NO_FLASH static int update_flash_protect(int prot, ulong addr_first, ulong addr_last) { uchar *sp_info_ptr; @@ -165,9 +168,11 @@ static int update_flash_protect(int prot, ulong addr_first, ulong addr_last) return 0; } +#endif static int update_flash(ulong addr_source, ulong addr_first, ulong size) { +#ifndef CONFIG_SYS_NO_FLASH ulong addr_last = addr_first + size - 1; /* round last address to the sector boundary */ @@ -203,7 +208,7 @@ static int update_flash(ulong addr_source, ulong addr_first, ulong size) printf("Error: could not protect flash sectors\n"); return 1; } - +#endif return 0; } @@ -223,13 +228,24 @@ static int update_fit_getparams(const void *fit, int noffset, ulong *addr, return 0; } -int update_tftp(ulong addr) +int update_tftp(ulong addr, char *interface, char *devstring) { - char *filename, *env_addr; - int images_noffset, ndepth, noffset; + char *filename, *env_addr, *fit_image_name; ulong update_addr, update_fladdr, update_size; - void *fit; + int images_noffset, ndepth, noffset; + bool update_tftp_dfu; int ret = 0; + void *fit; + + if (interface == NULL && devstring == NULL) { + update_tftp_dfu = false; + } else if (interface && devstring) { + update_tftp_dfu = true; + } else { + error("Interface: %s and devstring: %s not supported!\n", + interface, devstring); + return -EINVAL; + } /* use already present image */ if (addr) @@ -278,8 +294,8 @@ got_update_file: if (ndepth != 1) goto next_node; - printf("Processing update '%s' :", - fit_get_name(fit, noffset, NULL)); + fit_image_name = (char *)fit_get_name(fit, noffset, NULL); + printf("Processing update '%s' :", fit_image_name); if (!fit_image_verify(fit, noffset)) { printf("Error: invalid update hash, aborting\n"); @@ -295,10 +311,20 @@ got_update_file: ret = 1; goto next_node; } - if (update_flash(update_addr, update_fladdr, update_size)) { - printf("Error: can't flash update, aborting\n"); - ret = 1; - goto next_node; + + if (!update_tftp_dfu) { + if (update_flash(update_addr, update_fladdr, + update_size)) { + printf("Error: can't flash update, aborting\n"); + ret = 1; + goto next_node; + } + } else if (fit_image_check_type(fit, noffset, + IH_TYPE_FIRMWARE)) { + ret = dfu_tftp_write(fit_image_name, update_addr, + update_size, interface, devstring); + if (ret) + return ret; } next_node: noffset = fdt_next_node(fit, noffset, &ndepth); |
