flash: Tidy up coding style for flash functions
[oweals/u-boot.git] / common / update.c
index 0767fcbcb554042263472d139ce29922d1bdf2c0..c8dd346a0956951a0683679bdd37d13c07383e60 100644 (file)
@@ -1,13 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2008 Semihalf
  *
  * Written by: Rafal Czubak <rcz@semihalf.com>
  *             Bartlomiej Sieka <tur@semihalf.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
+#include <cpu_func.h>
+#include <image.h>
 
 #if !(defined(CONFIG_FIT) && defined(CONFIG_OF_LIBFDT))
 #error "CONFIG_FIT and CONFIG_OF_LIBFDT are required for auto-update feature"
 #endif
 
 #include <command.h>
+#include <env.h>
 #include <flash.h>
 #include <net.h>
 #include <net/tftp.h>
 #include <malloc.h>
 #include <dfu.h>
 #include <errno.h>
+#include <mtd/cfi_flash.h>
 
 /* env variable holding the location of the update file */
 #define UPDATE_FILE_ENV                "updatefile"
@@ -43,7 +46,6 @@
 
 extern ulong tftp_timeout_ms;
 extern int tftp_timeout_count_max;
-extern ulong load_addr;
 #ifdef CONFIG_MTD_NOR_FLASH
 extern flash_info_t flash_info[];
 static uchar *saved_prot_info;
@@ -59,7 +61,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 */
@@ -67,10 +69,10 @@ 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;
+       image_load_addr = addr;
        copy_filename(net_boot_file_name, filename, sizeof(net_boot_file_name));
        size = net_loop(TFTPGET);
 
@@ -83,7 +85,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);
 
@@ -242,7 +244,7 @@ int update_tftp(ulong addr, char *interface, char *devstring)
        } else if (interface && devstring) {
                update_tftp_dfu = true;
        } else {
-               error("Interface: %s and devstring: %s not supported!\n",
+               pr_err("Interface: %s and devstring: %s not supported!\n",
                      interface, devstring);
                return -EINVAL;
        }
@@ -254,7 +256,7 @@ int update_tftp(ulong addr, char *interface, char *devstring)
        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);
@@ -264,7 +266,8 @@ int update_tftp(ulong addr, char *interface, char *devstring)
        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;