]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - common/update.c
Merge branch 'rmobile-mx' of git://git.denx.de/u-boot-sh
[people/ms/u-boot.git] / common / update.c
index 1bf2f82138980fcfe65535d9e6efac1a4fd93e26..33bffaa89eca52014e88fdab626912be8f55bbdf 100644 (file)
@@ -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_MTD_NOR_FLASH)
+#error "CONFIG_UPDATE_TFTP and !CONFIG_MTD_NOR_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"
 
 extern ulong tftp_timeout_ms;
 extern int tftp_timeout_count_max;
-extern flash_info_t flash_info[];
 extern ulong load_addr;
-
+#ifdef CONFIG_MTD_NOR_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;
@@ -57,7 +59,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
        /* save used globals and env variable */
        saved_timeout_msecs = tftp_timeout_ms;
        saved_timeout_count = tftp_timeout_count_max;
-       saved_netretry = strdup(getenv("netretry"));
+       saved_netretry = strdup(env_get("netretry"));
        saved_bootfile = strdup(net_boot_file_name);
 
        /* set timeouts for auto-update */
@@ -65,12 +67,12 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
        tftp_timeout_count_max = cnt_max;
 
        /* we don't want to retry the connection if errors occur */
-       setenv("netretry", "no");
+       env_set("netretry", "no");
 
        /* download the update file */
        load_addr = addr;
        copy_filename(net_boot_file_name, filename, sizeof(net_boot_file_name));
-       size = NetLoop(TFTPGET);
+       size = net_loop(TFTPGET);
 
        if (size < 0)
                rv = 1;
@@ -81,7 +83,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
        tftp_timeout_ms = saved_timeout_msecs;
        tftp_timeout_count_max = saved_timeout_count;
 
-       setenv("netretry", saved_netretry);
+       env_set("netretry", saved_netretry);
        if (saved_netretry != NULL)
                free(saved_netretry);
 
@@ -94,6 +96,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
        return rv;
 }
 
+#ifdef CONFIG_MTD_NOR_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)
 {
+#ifdef CONFIG_MTD_NOR_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 {
+               pr_err("Interface: %s and devstring: %s not supported!\n",
+                     interface, devstring);
+               return -EINVAL;
+       }
 
        /* use already present image */
        if (addr)
@@ -238,7 +254,7 @@ int update_tftp(ulong addr)
        printf("Auto-update from TFTP: ");
 
        /* get the file name of the update file */
-       filename = getenv(UPDATE_FILE_ENV);
+       filename = env_get(UPDATE_FILE_ENV);
        if (filename == NULL) {
                printf("failed, env. variable '%s' not found\n",
                                                        UPDATE_FILE_ENV);
@@ -248,7 +264,8 @@ int update_tftp(ulong addr)
        printf("trying update file '%s'\n", filename);
 
        /* get load address of downloaded update file */
-       if ((env_addr = getenv("loadaddr")) != NULL)
+       env_addr = env_get("loadaddr");
+       if (env_addr)
                addr = simple_strtoul(env_addr, NULL, 16);
        else
                addr = CONFIG_UPDATE_LOAD_ADDR;
@@ -278,8 +295,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 +312,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);