[U-Boot] [PATCH 0/2] update from FIT image: add optional address, new command fitupd

Create new command "fitupd", so an update from a FIT-image can also be triggered from U-Boot shell, in addition to the automatic update after bootup when 'updatefile' is set. Also provide a way to use a FIT image in memory (e.g. loaded from MMC) instead of always load from a TFTP server. See doc/README.update for more information.
Adhere to present coding style => checkpatch warnings discarded.
Andreas Pretzsch (2): automatic update from FIT image: add optional address parameter add command fitupd to run an update from a FIT image
common/Makefile | 1 + common/cmd_fitupd.c | 37 +++++++++++++++++++++++++++++++++++++ common/main.c | 4 ++-- common/update.c | 8 ++++++-- doc/README.update | 5 +++++ 5 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 common/cmd_fitupd.c

Current update_tftp() flow: 1.) fetch "updatefile" from defined TFTP server 2.) check if FIT format 3.) flash contained images
Add an address parameter to update_tftp(). If this address is non-zero, skip the TFTP transfer and use the image at this address.
Signed-off-by: Andreas Pretzsch apr@cn-eng.de --- common/main.c | 4 ++-- common/update.c | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/common/main.c b/common/main.c index dcbacc9..9b86934 100644 --- a/common/main.c +++ b/common/main.c @@ -51,7 +51,7 @@ void inline __show_boot_progress (int val) {} void show_boot_progress (int val) __attribute__((weak, alias("__show_boot_progress")));
#if defined(CONFIG_UPDATE_TFTP) -void update_tftp (void); +void update_tftp (ulong addr); #endif /* CONFIG_UPDATE_TFTP */
#define MAX_DELAY_STOP_STR 32 @@ -356,7 +356,7 @@ void main_loop (void) #endif /* CONFIG_PREBOOT */
#if defined(CONFIG_UPDATE_TFTP) - update_tftp (); + update_tftp (0UL); #endif /* CONFIG_UPDATE_TFTP */
#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) diff --git a/common/update.c b/common/update.c index 7528474..531c7d6 100644 --- a/common/update.c +++ b/common/update.c @@ -238,14 +238,17 @@ static int update_fit_getparams(const void *fit, int noffset, ulong *addr, return 0; }
-void update_tftp(void) +void update_tftp(ulong addr) { char *filename, *env_addr; int images_noffset, ndepth, noffset; ulong update_addr, update_fladdr, update_size; - ulong addr; void *fit;
+ /* use already present image */ + if (addr) + goto got_update_file; + printf("Auto-update from TFTP: ");
/* get the file name of the update file */ @@ -271,6 +274,7 @@ void update_tftp(void) return; }
+got_update_file: fit = (void *)addr;
if (!fit_check_format((void *)fit)) {

Command calls update_tftp() analogous to automatic update described in doc/README.update.
Usage: fitupd [addr] - run update from FIT image at addr or from tftp 'updatefile'
Signed-off-by: Andreas Pretzsch apr@cn-eng.de --- common/Makefile | 1 + common/cmd_fitupd.c | 37 +++++++++++++++++++++++++++++++++++++ doc/README.update | 5 +++++ 3 files changed, 43 insertions(+), 0 deletions(-) create mode 100644 common/cmd_fitupd.c
diff --git a/common/Makefile b/common/Makefile index 4555716..4b81edc 100644 --- a/common/Makefile +++ b/common/Makefile @@ -94,6 +94,7 @@ COBJS-$(CONFIG_CMD_FAT) += cmd_fat.o COBJS-$(CONFIG_CMD_FDC)$(CONFIG_CMD_FDOS) += cmd_fdc.o COBJS-$(CONFIG_OF_LIBFDT) += cmd_fdt.o fdt_support.o COBJS-$(CONFIG_CMD_FDOS) += cmd_fdos.o +COBJS-$(CONFIG_CMD_FITUPD) += cmd_fitupd.o COBJS-$(CONFIG_CMD_FLASH) += cmd_flash.o ifdef CONFIG_FPGA COBJS-$(CONFIG_CMD_FPGA) += cmd_fpga.o diff --git a/common/cmd_fitupd.c b/common/cmd_fitupd.c new file mode 100644 index 0000000..7da3199 --- /dev/null +++ b/common/cmd_fitupd.c @@ -0,0 +1,37 @@ +/* + * (C) Copyright 2011 + * Andreas Pretzsch, carpe noctem engineering, apr@cn-eng.de + * + * This file is released under the terms of GPL v2 and any later version. + * See the file COPYING in the root directory of the source tree for details. + */ + +#include <common.h> +#include <command.h> + +#if !defined(CONFIG_UPDATE_TFTP) +#error "CONFIG_UPDATE_TFTP required" +#endif + +extern void update_tftp(ulong addr); + +static int do_fitupd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + ulong addr = 0UL; + + if (argc > 2) + return cmd_usage(cmdtp); + + if (argc == 2) + addr = simple_strtoul(argv[1], NULL, 16); + + update_tftp(addr); + return 0; +} + +U_BOOT_CMD(fitupd, 2, 0, do_fitupd, + "update from FIT image", + "[addr]\n" + "\t- run update from FIT image at addr\n" + "\t or from tftp 'updatefile'" +); diff --git a/doc/README.update b/doc/README.update index 48f03b7..a7f4d9e 100644 --- a/doc/README.update +++ b/doc/README.update @@ -51,6 +51,11 @@ the mkimage tool. dtc tool with support for binary includes, e.g. in version to be prepared. Refer to the doc/uImage.FIT/ directory for more details on FIT images.
+This mechanism can be also triggered by the commmand "fitupd". +If an optional, non-zero address is provided as argument, the TFTP transfer +is skipped and the image at this address is used. +The fitupd command is enabled by CONFIG_CMD_FITUPD. +
Example .its files ------------------

Create new command "fitupd", so an update from a FIT-image can also be triggered from U-Boot shell, in addition to the automatic update after bootup when 'updatefile' is set. Also provide a way to use a FIT image in memory (e.g. loaded from MMC) instead of always load from a TFTP server. See doc/README.update for more information.
Adhere to present coding style => checkpatch warnings discarded.
Changes for v2: - void update_tftp() => int update_tftp(): return success/fail
Andreas Pretzsch (2): automatic update from FIT image: add optional address parameter add command fitupd to run an update from a FIT image
common/Makefile | 1 + common/cmd_fitupd.c | 36 ++++++++++++++++++++++++++++++++++++ common/main.c | 4 ++-- common/update.c | 20 ++++++++++++++------ doc/README.update | 5 +++++ 5 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 common/cmd_fitupd.c

Current update_tftp() flow: 1.) fetch "updatefile" from defined TFTP server 2.) check if FIT format 3.) flash contained images
Add an address parameter to update_tftp(). If this address is non-zero, skip the TFTP transfer and use the image at this address. Also extend update_tftp() to return success/fail.
Signed-off-by: Andreas Pretzsch apr@cn-eng.de --- Changes for v2: - void update_tftp() => int update_tftp(): return success/fail --- common/main.c | 4 ++-- common/update.c | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/common/main.c b/common/main.c index 2730c6f..0a310e0 100644 --- a/common/main.c +++ b/common/main.c @@ -51,7 +51,7 @@ void inline __show_boot_progress (int val) {} void show_boot_progress (int val) __attribute__((weak, alias("__show_boot_progress")));
#if defined(CONFIG_UPDATE_TFTP) -void update_tftp (void); +int update_tftp (ulong addr); #endif /* CONFIG_UPDATE_TFTP */
#define MAX_DELAY_STOP_STR 32 @@ -345,7 +345,7 @@ void main_loop (void) #endif /* CONFIG_PREBOOT */
#if defined(CONFIG_UPDATE_TFTP) - update_tftp (); + update_tftp (0UL); #endif /* CONFIG_UPDATE_TFTP */
#if defined(CONFIG_BOOTDELAY) && (CONFIG_BOOTDELAY >= 0) diff --git a/common/update.c b/common/update.c index 7528474..a19f136 100644 --- a/common/update.c +++ b/common/update.c @@ -238,13 +238,17 @@ static int update_fit_getparams(const void *fit, int noffset, ulong *addr, return 0; }
-void update_tftp(void) +int update_tftp(ulong addr) { char *filename, *env_addr; int images_noffset, ndepth, noffset; ulong update_addr, update_fladdr, update_size; - ulong addr; void *fit; + int ret = 0; + + /* use already present image */ + if (addr) + goto got_update_file;
printf("Auto-update from TFTP: ");
@@ -253,7 +257,7 @@ void update_tftp(void) if (filename == NULL) { printf("failed, env. variable '%s' not found\n", UPDATE_FILE_ENV); - return; + return 1; }
printf("trying update file '%s'\n", filename); @@ -268,15 +272,16 @@ void update_tftp(void) if (update_load(filename, CONFIG_UPDATE_TFTP_MSEC_MAX, CONFIG_UPDATE_TFTP_CNT_MAX, addr)) { printf("Can't load update file, aborting auto-update\n"); - return; + return 1; }
+got_update_file: fit = (void *)addr;
if (!fit_check_format((void *)fit)) { printf("Bad FIT format of the update file, aborting " "auto-update\n"); - return; + return 1; }
/* process updates */ @@ -293,6 +298,7 @@ void update_tftp(void)
if (!fit_image_check_hashes(fit, noffset)) { printf("Error: invalid update hash, aborting\n"); + ret = 1; goto next_node; }
@@ -301,15 +307,17 @@ void update_tftp(void) &update_fladdr, &update_size)) { printf("Error: can't get update parameteres, " "aborting\n"); + 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; } next_node: noffset = fdt_next_node(fit, noffset, &ndepth); }
- return; + return ret; }

Dear Andreas Pretzsch,
In message 1310831460-14450-2-git-send-email-apr@cn-eng.de you wrote:
Current update_tftp() flow: 1.) fetch "updatefile" from defined TFTP server 2.) check if FIT format 3.) flash contained images
Add an address parameter to update_tftp(). If this address is non-zero, skip the TFTP transfer and use the image at this address. Also extend update_tftp() to return success/fail.
Signed-off-by: Andreas Pretzsch apr@cn-eng.de
Changes for v2:
- void update_tftp() => int update_tftp(): return success/fail
common/main.c | 4 ++-- common/update.c | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk

Command calls update_tftp() analogous to automatic update described in doc/README.update.
Usage: fitupd [addr] - run update from FIT image at addr or from tftp 'updatefile'
Signed-off-by: Andreas Pretzsch apr@cn-eng.de --- Changes for v2: - void update_tftp() => int update_tftp(): return success/fail --- common/Makefile | 1 + common/cmd_fitupd.c | 36 ++++++++++++++++++++++++++++++++++++ doc/README.update | 5 +++++ 3 files changed, 42 insertions(+), 0 deletions(-) create mode 100644 common/cmd_fitupd.c
diff --git a/common/Makefile b/common/Makefile index 224b7cc..e92ee5b 100644 --- a/common/Makefile +++ b/common/Makefile @@ -94,6 +94,7 @@ COBJS-$(CONFIG_CMD_FAT) += cmd_fat.o COBJS-$(CONFIG_CMD_FDC)$(CONFIG_CMD_FDOS) += cmd_fdc.o COBJS-$(CONFIG_OF_LIBFDT) += cmd_fdt.o fdt_support.o COBJS-$(CONFIG_CMD_FDOS) += cmd_fdos.o +COBJS-$(CONFIG_CMD_FITUPD) += cmd_fitupd.o COBJS-$(CONFIG_CMD_FLASH) += cmd_flash.o ifdef CONFIG_FPGA COBJS-$(CONFIG_CMD_FPGA) += cmd_fpga.o diff --git a/common/cmd_fitupd.c b/common/cmd_fitupd.c new file mode 100644 index 0000000..4d1192b --- /dev/null +++ b/common/cmd_fitupd.c @@ -0,0 +1,36 @@ +/* + * (C) Copyright 2011 + * Andreas Pretzsch, carpe noctem engineering, apr@cn-eng.de + * + * This file is released under the terms of GPL v2 and any later version. + * See the file COPYING in the root directory of the source tree for details. + */ + +#include <common.h> +#include <command.h> + +#if !defined(CONFIG_UPDATE_TFTP) +#error "CONFIG_UPDATE_TFTP required" +#endif + +extern int update_tftp(ulong addr); + +static int do_fitupd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) +{ + ulong addr = 0UL; + + if (argc > 2) + return cmd_usage(cmdtp); + + if (argc == 2) + addr = simple_strtoul(argv[1], NULL, 16); + + return update_tftp(addr); +} + +U_BOOT_CMD(fitupd, 2, 0, do_fitupd, + "update from FIT image", + "[addr]\n" + "\t- run update from FIT image at addr\n" + "\t or from tftp 'updatefile'" +); diff --git a/doc/README.update b/doc/README.update index 48f03b7..a7f4d9e 100644 --- a/doc/README.update +++ b/doc/README.update @@ -51,6 +51,11 @@ the mkimage tool. dtc tool with support for binary includes, e.g. in version to be prepared. Refer to the doc/uImage.FIT/ directory for more details on FIT images.
+This mechanism can be also triggered by the commmand "fitupd". +If an optional, non-zero address is provided as argument, the TFTP transfer +is skipped and the image at this address is used. +The fitupd command is enabled by CONFIG_CMD_FITUPD. +
Example .its files ------------------

Dear Andreas Pretzsch,
In message 1310831460-14450-3-git-send-email-apr@cn-eng.de you wrote:
Command calls update_tftp() analogous to automatic update described in doc/README.update.
Usage: fitupd [addr] - run update from FIT image at addr or from tftp 'updatefile'
Signed-off-by: Andreas Pretzsch apr@cn-eng.de
Changes for v2:
- void update_tftp() => int update_tftp(): return success/fail
common/Makefile | 1 + common/cmd_fitupd.c | 36 ++++++++++++++++++++++++++++++++++++ doc/README.update | 5 +++++ 3 files changed, 42 insertions(+), 0 deletions(-) create mode 100644 common/cmd_fitupd.c
Applied, thanks.
Best regards,
Wolfgang Denk
participants (2)
-
Andreas Pretzsch
-
Wolfgang Denk