|
@@ -13,11 +13,17 @@
|
|
#error "CONFIG_FIT and CONFIG_OF_LIBFDT are required for auto-update feature"
|
|
#error "CONFIG_FIT and CONFIG_OF_LIBFDT are required for auto-update feature"
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
+#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>
|
|
#include <command.h>
|
|
#include <flash.h>
|
|
#include <flash.h>
|
|
#include <net.h>
|
|
#include <net.h>
|
|
#include <net/tftp.h>
|
|
#include <net/tftp.h>
|
|
#include <malloc.h>
|
|
#include <malloc.h>
|
|
|
|
+#include <dfu.h>
|
|
|
|
+#include <errno.h>
|
|
|
|
|
|
/* env variable holding the location of the update file */
|
|
/* env variable holding the location of the update file */
|
|
#define UPDATE_FILE_ENV "updatefile"
|
|
#define UPDATE_FILE_ENV "updatefile"
|
|
@@ -222,13 +228,24 @@ static int update_fit_getparams(const void *fit, int noffset, ulong *addr,
|
|
return 0;
|
|
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;
|
|
ulong update_addr, update_fladdr, update_size;
|
|
- void *fit;
|
|
|
|
|
|
+ int images_noffset, ndepth, noffset;
|
|
|
|
+ bool update_tftp_dfu;
|
|
int ret = 0;
|
|
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 */
|
|
/* use already present image */
|
|
if (addr)
|
|
if (addr)
|
|
@@ -277,8 +294,8 @@ got_update_file:
|
|
if (ndepth != 1)
|
|
if (ndepth != 1)
|
|
goto next_node;
|
|
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)) {
|
|
if (!fit_image_verify(fit, noffset)) {
|
|
printf("Error: invalid update hash, aborting\n");
|
|
printf("Error: invalid update hash, aborting\n");
|
|
@@ -294,10 +311,20 @@ got_update_file:
|
|
ret = 1;
|
|
ret = 1;
|
|
goto next_node;
|
|
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:
|
|
next_node:
|
|
noffset = fdt_next_node(fit, noffset, &ndepth);
|
|
noffset = fdt_next_node(fit, noffset, &ndepth);
|