]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/update.c
karo: tx51: remove duplicate CONFIG_SYS_SDRAM_CLK definition
[karo-tx-uboot.git] / common / update.c
index 75284748734e11961cea3fb6258d4149e389112d..cc830a78657caaca7341a5c4ca20b06891186721 100644 (file)
@@ -4,24 +4,7 @@
  * Written by: Rafal Czubak <rcz@semihalf.com>
  *             Bartlomiej Sieka <tur@semihalf.com>
  *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- *
+ * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -37,6 +20,7 @@
 #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 +70,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;
@@ -238,13 +222,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 +241,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 +256,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 */
@@ -291,8 +280,9 @@ void update_tftp(void)
                printf("Processing update '%s' :",
                        fit_get_name(fit, noffset, NULL));
 
-               if (!fit_image_check_hashes(fit, noffset)) {
+               if (!fit_image_verify(fit, noffset)) {
                        printf("Error: invalid update hash, aborting\n");
+                       ret = 1;
                        goto next_node;
                }
 
@@ -301,15 +291,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;
 }