]> git.sur5r.net Git - u-boot/blobdiff - common/update.c
ppc: Move mirror_hack to arch_global_data
[u-boot] / common / update.c
index 938cc068166c41e1a28fcf4bbe83302c2918d2cd..94d6a82aeb1b19478c07706419334815ac15d8e5 100644 (file)
 #error "CONFIG_FIT and CONFIG_OF_LIBFDT are required for auto-update feature"
 #endif
 
-#if defined(CFG_NO_FLASH)
-#error "CFG_NO_FLASH defined, but FLASH is required for auto-update feature"
+#if defined(CONFIG_SYS_NO_FLASH)
+#error "CONFIG_SYS_NO_FLASH defined, but FLASH is required for auto-update feature"
 #endif
 
 #include <command.h>
 #include <flash.h>
 #include <net.h>
+#include <net/tftp.h>
 #include <malloc.h>
 
 /* env variable holding the location of the update file */
@@ -86,7 +87,7 @@ static int update_load(char *filename, ulong msec_max, int cnt_max, ulong addr)
        /* download the update file */
        load_addr = addr;
        copy_filename(BootFile, filename, sizeof(BootFile));
-       size = NetLoop(TFTP);
+       size = NetLoop(TFTPGET);
 
        if (size < 0)
                rv = 1;
@@ -120,12 +121,12 @@ static int update_flash_protect(int prot, ulong addr_first, ulong addr_last)
 
        if (prot == 0) {
                saved_prot_info =
-                       calloc(CFG_MAX_FLASH_BANKS * CFG_MAX_FLASH_SECT, 1);
+                       calloc(CONFIG_SYS_MAX_FLASH_BANKS * CONFIG_SYS_MAX_FLASH_SECT, 1);
                if (!saved_prot_info)
                        return 1;
        }
 
-       for (bank = 0; bank < CFG_MAX_FLASH_BANKS; ++bank) {
+       for (bank = 0; bank < CONFIG_SYS_MAX_FLASH_BANKS; ++bank) {
                cnt = 0;
                info = &flash_info[bank];
 
@@ -134,7 +135,7 @@ static int update_flash_protect(int prot, ulong addr_first, ulong addr_last)
                        return 0;
 
                /* Point to current bank protection information */
-               sp_info_ptr = saved_prot_info + (bank * CFG_MAX_FLASH_SECT);
+               sp_info_ptr = saved_prot_info + (bank * CONFIG_SYS_MAX_FLASH_SECT);
 
                /*
                 * Adjust addr_first or addr_last if we are on bank boundary.
@@ -159,7 +160,7 @@ static int update_flash_protect(int prot, ulong addr_first, ulong addr_last)
 
                        /* Protect/unprotect sectors */
                        if (sp_info_ptr[i] == 1) {
-#if defined(CFG_FLASH_PROTECTION)
+#if defined(CONFIG_SYS_FLASH_PROTECTION)
                                if (flash_real_protect(info, i, prot))
                                        return 1;
 #else
@@ -238,13 +239,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 +258,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 +273,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 +299,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 +308,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;
 }