env: Rename getenv/_f() to env_get()

We are now using an env_ prefix for environment functions. Rename these
two functions for consistency. Also add function comments in common.h.

Quite a few places use getenv() in a condition context, provoking a
warning from checkpatch. These are fixed up in this patch also.

Suggested-by: Wolfgang Denk <wd@denx.de>
Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/common/autoboot.c b/common/autoboot.c
index 41f1820..35c1e97 100644
--- a/common/autoboot.c
+++ b/common/autoboot.c
@@ -50,7 +50,7 @@
 
 static int passwd_abort(uint64_t etime)
 {
-	const char *sha_env_str = getenv("bootstopkeysha256");
+	const char *sha_env_str = env_get("bootstopkeysha256");
 	u8 sha_env[SHA256_SUM_LEN];
 	u8 sha[SHA256_SUM_LEN];
 	char presskey[MAX_DELAY_STOP_STR];
@@ -109,8 +109,8 @@
 		int retry;
 	}
 	delaykey[] = {
-		{ .str = getenv("bootdelaykey"),  .retry = 1 },
-		{ .str = getenv("bootstopkey"),   .retry = 0 },
+		{ .str = env_get("bootdelaykey"),  .retry = 1 },
+		{ .str = env_get("bootstopkey"),   .retry = 0 },
 	};
 
 	char presskey[MAX_DELAY_STOP_STR];
@@ -304,7 +304,7 @@
 	bootlimit = getenv_ulong("bootlimit", 10, 0);
 #endif /* CONFIG_BOOTCOUNT_LIMIT */
 
-	s = getenv("bootdelay");
+	s = env_get("bootdelay");
 	bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
 
 #ifdef CONFIG_OF_CONTROL
@@ -321,17 +321,17 @@
 
 #ifdef CONFIG_POST
 	if (gd->flags & GD_FLG_POSTFAIL) {
-		s = getenv("failbootcmd");
+		s = env_get("failbootcmd");
 	} else
 #endif /* CONFIG_POST */
 #ifdef CONFIG_BOOTCOUNT_LIMIT
 	if (bootlimit && (bootcount > bootlimit)) {
 		printf("Warning: Bootlimit (%u) exceeded. Using altbootcmd.\n",
 		       (unsigned)bootlimit);
-		s = getenv("altbootcmd");
+		s = env_get("altbootcmd");
 	} else
 #endif /* CONFIG_BOOTCOUNT_LIMIT */
-		s = getenv("bootcmd");
+		s = env_get("bootcmd");
 
 	process_fdt_options(gd->fdt_blob);
 	stored_bootdelay = bootdelay;
@@ -357,7 +357,7 @@
 
 #ifdef CONFIG_MENUKEY
 	if (menukey == CONFIG_MENUKEY) {
-		s = getenv("menucmd");
+		s = env_get("menucmd");
 		if (s)
 			run_command_list(s, -1, 0);
 	}
diff --git a/common/bootm.c b/common/bootm.c
index e34617a..0c380e7 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -524,7 +524,7 @@
 {
 	char *buf;
 	const char *env_val;
-	char *cmdline = getenv("bootargs");
+	char *cmdline = env_get("bootargs");
 	int want_silent;
 
 	/*
@@ -691,7 +691,7 @@
 #ifdef CONFIG_TRACE
 	/* Pretend to run the OS, then run a user command */
 	if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) {
-		char *cmd_list = getenv("fakegocmd");
+		char *cmd_list = env_get("fakegocmd");
 
 		ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_FAKE_GO,
 				images, boot_fn);
diff --git a/common/bootm_os.c b/common/bootm_os.c
index 86a37cb..1feea8a 100644
--- a/common/bootm_os.c
+++ b/common/bootm_os.c
@@ -21,7 +21,7 @@
 	int (*appl)(int, char *const[]);
 
 	/* Don't start if "autostart" is set to "no" */
-	s = getenv("autostart");
+	s = env_get("autostart");
 	if ((s != NULL) && !strcmp(s, "no")) {
 		env_set_hex("filesize", images->os.image_len);
 		return 0;
@@ -96,7 +96,7 @@
 		cmdline = malloc(len);
 		copy_args(cmdline, argc, argv, ' ');
 	} else {
-		cmdline = getenv("bootargs");
+		cmdline = env_get("bootargs");
 		if (cmdline == NULL)
 			cmdline = "";
 	}
@@ -227,14 +227,14 @@
 #endif
 
 	/* See README.plan9 */
-	s = getenv("confaddr");
+	s = env_get("confaddr");
 	if (s != NULL) {
 		char *confaddr = (char *)simple_strtoul(s, NULL, 16);
 
 		if (argc > 0) {
 			copy_args(confaddr, argc, argv, '\n');
 		} else {
-			s = getenv("bootargs");
+			s = env_get("bootargs");
 			if (s != NULL)
 				strcpy(confaddr, s);
 		}
@@ -278,7 +278,7 @@
 
 		ret = fdt_add_subnode(*of_flat_tree, 0, "chosen");
 		if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) {
-			bootline = getenv("bootargs");
+			bootline = env_get("bootargs");
 			if (bootline) {
 				ret = fdt_find_and_setprop(*of_flat_tree,
 						"/chosen", "bootargs",
diff --git a/common/bootretry.c b/common/bootretry.c
index 2d82798..b3b8271 100644
--- a/common/bootretry.c
+++ b/common/bootretry.c
@@ -23,7 +23,7 @@
  */
 void bootretry_init_cmd_timeout(void)
 {
-	char *s = getenv("bootretry");
+	char *s = env_get("bootretry");
 
 	if (s != NULL)
 		retry_time = (int)simple_strtol(s, NULL, 10);
diff --git a/common/cli.c b/common/cli.c
index a433ef2..57874d8 100644
--- a/common/cli.c
+++ b/common/cli.c
@@ -129,7 +129,7 @@
 	for (i = 1; i < argc; ++i) {
 		char *arg;
 
-		arg = getenv(argv[i]);
+		arg = env_get(argv[i]);
 		if (arg == NULL) {
 			printf("## Error: \"%s\" not defined\n", argv[i]);
 			return 1;
diff --git a/common/cli_hush.c b/common/cli_hush.c
index 2802896..07c048e 100644
--- a/common/cli_hush.c
+++ b/common/cli_hush.c
@@ -560,7 +560,7 @@
 {
 	char *newdir;
 	if (child->argv[1] == NULL)
-		newdir = getenv("HOME");
+		newdir = env_get("HOME");
 	else
 		newdir = child->argv[1];
 	if (chdir(newdir)) {
@@ -948,7 +948,7 @@
 #ifndef CONFIG_FEATURE_SH_FANCY_PROMPT
 	PS1 = NULL;
 #else
-	PS1 = getenv("PS1");
+	PS1 = env_get("PS1");
 	if(PS1==0)
 		PS1 = "\\w \\$ ";
 #endif
@@ -987,9 +987,9 @@
 
 #ifdef CONFIG_CMDLINE_PS_SUPPORT
 	if (i->promptmode == 1)
-		ps_prompt = getenv("PS1");
+		ps_prompt = env_get("PS1");
 	else
-		ps_prompt = getenv("PS2");
+		ps_prompt = env_get("PS2");
 	if (ps_prompt)
 		prompt = ps_prompt;
 #endif
@@ -2172,7 +2172,7 @@
 	name=strdup(s);
 
 #ifdef __U_BOOT__
-	if (getenv(name) != NULL) {
+	if (env_get(name) != NULL) {
 		printf ("ERROR: "
 				"There is a global environment variable with the same name.\n");
 		free(name);
@@ -2793,7 +2793,7 @@
 		}
 	}
 
-	p = getenv(src);
+	p = env_get(src);
 	if (!p)
 		p = get_local_var(src);
 
@@ -3157,7 +3157,7 @@
 static void update_ifs_map(void)
 {
 	/* char *ifs and char map[256] are both globals. */
-	ifs = (uchar *)getenv("IFS");
+	ifs = (uchar *)env_get("IFS");
 	if (ifs == NULL) ifs=(uchar *)" \t\n";
 	/* Precompute a list of 'flow through' behavior so it can be treated
 	 * quickly up front.  Computation is necessary because of IFS.
diff --git a/common/cli_simple.c b/common/cli_simple.c
index bb96aae..cb642d2 100644
--- a/common/cli_simple.c
+++ b/common/cli_simple.c
@@ -131,7 +131,7 @@
 				envname[i] = 0;
 
 				/* Get its value */
-				envval = getenv(envname);
+				envval = env_get(envname);
 
 				/* Copy into the line if it exists */
 				if (envval != NULL)
@@ -168,7 +168,7 @@
  * WARNING:
  *
  * We must create a temporary copy of the command since the command we get
- * may be the result from getenv(), which returns a pointer directly to
+ * may be the result from env_get(), which returns a pointer directly to
  * the environment data, which may change magicly when the command we run
  * creates or modifies environment variables (like "bootp" does).
  */
diff --git a/common/console.c b/common/console.c
index 3f7ca2b..3167921 100644
--- a/common/console.c
+++ b/common/console.c
@@ -666,7 +666,7 @@
 static void console_update_silent(void)
 {
 #ifdef CONFIG_SILENT_CONSOLE
-	if (getenv("silent") != NULL)
+	if (env_get("silent") != NULL)
 		gd->flags |= GD_FLG_SILENT;
 	else
 		gd->flags &= ~GD_FLG_SILENT;
@@ -745,9 +745,9 @@
 
 	/* stdin stdout and stderr are in environment */
 	/* scan for it */
-	stdinname  = getenv("stdin");
-	stdoutname = getenv("stdout");
-	stderrname = getenv("stderr");
+	stdinname  = env_get("stdin");
+	stdoutname = env_get("stdout");
+	stderrname = env_get("stderr");
 
 	if (OVERWRITE_CONSOLE == 0) {	/* if not overwritten by config switch */
 		inputdev  = search_device(DEV_FLAGS_INPUT,  stdinname);
@@ -836,7 +836,7 @@
 	 * console to serial console in this case or suppress it if
 	 * "silent" mode was requested.
 	 */
-	if (getenv("splashimage") != NULL) {
+	if (env_get("splashimage") != NULL) {
 		if (!(gd->flags & GD_FLG_SILENT))
 			outputdev = search_device (DEV_FLAGS_OUTPUT, "serial");
 	}
diff --git a/common/fb_mmc.c b/common/fb_mmc.c
index 2113b6c..5065ad5 100644
--- a/common/fb_mmc.c
+++ b/common/fb_mmc.c
@@ -49,7 +49,7 @@
 		/* check for alias */
 		strcpy(env_alias_name, "fastboot_partition_alias_");
 		strncat(env_alias_name, name, 32);
-		aliased_part_name = getenv(env_alias_name);
+		aliased_part_name = env_get(env_alias_name);
 		if (aliased_part_name != NULL)
 			ret = part_get_info_by_name(dev_desc,
 					aliased_part_name, info);
diff --git a/common/fdt_support.c b/common/fdt_support.c
index 7ccf8b1..916a448 100644
--- a/common/fdt_support.c
+++ b/common/fdt_support.c
@@ -197,7 +197,7 @@
 		return err;
 	}
 
-	serial = getenv("serial#");
+	serial = env_get("serial#");
 	if (serial) {
 		err = fdt_setprop(fdt, 0, "serial-number", serial,
 				  strlen(serial) + 1);
@@ -289,7 +289,7 @@
 	if (nodeoffset < 0)
 		return nodeoffset;
 
-	str = getenv("bootargs");
+	str = env_get("bootargs");
 	if (str) {
 		err = fdt_setprop(fdt, nodeoffset, "bootargs", str,
 				  strlen(str) + 1);
@@ -509,7 +509,7 @@
 			} else {
 				continue;
 			}
-			tmp = getenv(mac);
+			tmp = env_get(mac);
 			if (!tmp)
 				continue;
 
diff --git a/common/hash.c b/common/hash.c
index fda636d..dcf016d 100644
--- a/common/hash.c
+++ b/common/hash.c
@@ -362,7 +362,7 @@
 		if (strlen(verify_str) == digits)
 			vsum_str = verify_str;
 		else {
-			vsum_str = getenv(verify_str);
+			vsum_str = env_get(verify_str);
 			if (vsum_str == NULL || strlen(vsum_str) != digits) {
 				printf("Expected %d hex digits in env var\n",
 				       digits);
diff --git a/common/hwconfig.c b/common/hwconfig.c
index 85aaabb..e5186d7 100644
--- a/common/hwconfig.c
+++ b/common/hwconfig.c
@@ -81,7 +81,7 @@
 					"and before environment is ready\n");
 			return NULL;
 		}
-		env_hwconfig = getenv("hwconfig");
+		env_hwconfig = env_get("hwconfig");
 	}
 
 	if (env_hwconfig) {
diff --git a/common/image-android.c b/common/image-android.c
index 018c759..e74d0aa 100644
--- a/common/image-android.c
+++ b/common/image-android.c
@@ -72,7 +72,7 @@
 		len += strlen(hdr->cmdline);
 	}
 
-	char *bootargs = getenv("bootargs");
+	char *bootargs = env_get("bootargs");
 	if (bootargs)
 		len += strlen(bootargs);
 
diff --git a/common/image-fdt.c b/common/image-fdt.c
index c6e8832..2c49946 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -132,7 +132,7 @@
 	of_len = *of_size + CONFIG_SYS_FDT_PAD;
 
 	/* If fdt_high is set use it to select the relocation address */
-	fdt_high = getenv("fdt_high");
+	fdt_high = env_get("fdt_high");
 	if (fdt_high) {
 		void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16);
 
diff --git a/common/image.c b/common/image.c
index 0f88984..98c0eaa 100644
--- a/common/image.c
+++ b/common/image.c
@@ -467,7 +467,7 @@
 
 ulong getenv_bootm_low(void)
 {
-	char *s = getenv("bootm_low");
+	char *s = env_get("bootm_low");
 	if (s) {
 		ulong tmp = simple_strtoul(s, NULL, 16);
 		return tmp;
@@ -486,7 +486,7 @@
 {
 	phys_size_t tmp, size;
 	phys_addr_t start;
-	char *s = getenv("bootm_size");
+	char *s = env_get("bootm_size");
 	if (s) {
 		tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
 		return tmp;
@@ -500,7 +500,7 @@
 	size = gd->bd->bi_memsize;
 #endif
 
-	s = getenv("bootm_low");
+	s = env_get("bootm_low");
 	if (s)
 		tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
 	else
@@ -512,7 +512,7 @@
 phys_size_t getenv_bootm_mapsize(void)
 {
 	phys_size_t tmp;
-	char *s = getenv("bootm_mapsize");
+	char *s = env_get("bootm_mapsize");
 	if (s) {
 		tmp = (phys_size_t)simple_strtoull(s, NULL, 16);
 		return tmp;
@@ -1224,7 +1224,8 @@
 	ulong	initrd_high;
 	int	initrd_copy_to_ram = 1;
 
-	if ((s = getenv("initrd_high")) != NULL) {
+	s = env_get("initrd_high");
+	if (s) {
 		/* a value of "no" or a similar string will act like 0,
 		 * turning the "load high" feature off. This is intentional.
 		 */
@@ -1524,7 +1525,8 @@
 	if (cmdline == NULL)
 		return -1;
 
-	if ((s = getenv("bootargs")) == NULL)
+	s = env_get("bootargs");
+	if (!s)
 		s = "";
 
 	strcpy(cmdline, s);
diff --git a/common/lcd.c b/common/lcd.c
index 7e399ce..c3ff959 100644
--- a/common/lcd.c
+++ b/common/lcd.c
@@ -223,7 +223,7 @@
 	/* Paint the logo and retrieve LCD base address */
 	debug("[LCD] Drawing the logo...\n");
 	if (do_splash) {
-		s = getenv("splashimage");
+		s = env_get("splashimage");
 		if (s) {
 			do_splash = 0;
 			addr = simple_strtoul(s, NULL, 16);
diff --git a/common/main.c b/common/main.c
index 07fc31b..6a11598 100644
--- a/common/main.c
+++ b/common/main.c
@@ -25,7 +25,7 @@
 #ifdef CONFIG_PREBOOT
 	char *p;
 
-	p = getenv("preboot");
+	p = env_get("preboot");
 	if (p != NULL) {
 # ifdef CONFIG_AUTOBOOT_KEYED
 		int prev = disable_ctrlc(1);	/* disable Control C checking */
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 3c887b3..582b685 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -278,7 +278,7 @@
 	  needed in SPL as it has a much simpler task with less
 	  configuration. But some boards use this to support 'Falcon' boot
 	  on EXT2 and FAT, where SPL boots directly into Linux without
-	  starting U-Boot first. Enabling this option will make getenv()
+	  starting U-Boot first. Enabling this option will make env_get()
 	  and env_set() available in SPL.
 
 config SPL_SAVEENV
diff --git a/common/spl/spl_dfu.c b/common/spl/spl_dfu.c
index f5ec0fb..2c97473 100644
--- a/common/spl/spl_dfu.c
+++ b/common/spl/spl_dfu.c
@@ -40,7 +40,7 @@
 
 	/* set default environment */
 	set_default_env(0);
-	str_env = getenv(dfu_alt_info);
+	str_env = env_get(dfu_alt_info);
 	if (!str_env) {
 		error("\"dfu_alt_info\" env variable not defined!\n");
 		return -EINVAL;
diff --git a/common/spl/spl_ext.c b/common/spl/spl_ext.c
index f17c6b9..559ba0b 100644
--- a/common/spl/spl_ext.c
+++ b/common/spl/spl_ext.c
@@ -89,7 +89,7 @@
 		return -1;
 	}
 #if defined(CONFIG_SPL_ENV_SUPPORT)
-	file = getenv("falcon_args_file");
+	file = env_get("falcon_args_file");
 	if (file) {
 		err = ext4fs_open(file, &filelen);
 		if (err < 0) {
@@ -102,7 +102,7 @@
 			       file, err);
 			goto defaults;
 		}
-		file = getenv("falcon_image_file");
+		file = env_get("falcon_image_file");
 		if (file) {
 			err = spl_load_image_ext(spl_image, block_dev,
 						 partition, file);
diff --git a/common/spl/spl_fat.c b/common/spl/spl_fat.c
index 5e31216..60b85f0 100644
--- a/common/spl/spl_fat.c
+++ b/common/spl/spl_fat.c
@@ -113,7 +113,7 @@
 		return err;
 
 #if defined(CONFIG_SPL_ENV_SUPPORT) && defined(CONFIG_SPL_OS_BOOT)
-	file = getenv("falcon_args_file");
+	file = env_get("falcon_args_file");
 	if (file) {
 		err = file_fat_read(file, (void *)CONFIG_SYS_SPL_ARGS_ADDR, 0);
 		if (err <= 0) {
@@ -121,7 +121,7 @@
 			       file, err);
 			goto defaults;
 		}
-		file = getenv("falcon_image_file");
+		file = env_get("falcon_image_file");
 		if (file) {
 			err = spl_load_image_fat(spl_image, block_dev,
 						 partition, file);
diff --git a/common/splash.c b/common/splash.c
index 89af437..d251b3b 100644
--- a/common/splash.c
+++ b/common/splash.c
@@ -60,7 +60,7 @@
 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
 void splash_get_pos(int *x, int *y)
 {
-	char *s = getenv("splashpos");
+	char *s = env_get("splashpos");
 
 	if (!s)
 		return;
diff --git a/common/splash_source.c b/common/splash_source.c
index 867a798..8c0ac58 100644
--- a/common/splash_source.c
+++ b/common/splash_source.c
@@ -220,7 +220,7 @@
 	loff_t actread;
 	char *splash_file;
 
-	splash_file = getenv("splashfile");
+	splash_file = env_get("splashfile");
 	if (!splash_file)
 		splash_file = SPLASH_SOURCE_DEFAULT_FILE_NAME;
 
@@ -286,7 +286,7 @@
 	if (!locations || size == 0)
 		return NULL;
 
-	env_splashsource = getenv("splashsource");
+	env_splashsource = env_get("splashsource");
 	if (env_splashsource == NULL)
 		return &locations[0];
 
@@ -383,7 +383,7 @@
 	char *env_splashimage_value;
 	u32 bmp_load_addr;
 
-	env_splashimage_value = getenv("splashimage");
+	env_splashimage_value = env_get("splashimage");
 	if (env_splashimage_value == NULL)
 		return -ENOENT;
 
diff --git a/common/update.c b/common/update.c
index 061a554..974f465 100644
--- a/common/update.c
+++ b/common/update.c
@@ -59,7 +59,7 @@
 	/* 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 */
@@ -254,7 +254,7 @@
 	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 +264,8 @@
 	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;
diff --git a/common/usb_hub.c b/common/usb_hub.c
index 70bc6e2..86a3477 100644
--- a/common/usb_hub.c
+++ b/common/usb_hub.c
@@ -189,7 +189,7 @@
 	 * but allow this time to be increased via env variable as some
 	 * devices break the spec and require longer warm-up times
 	 */
-	env = getenv("usb_pgood_delay");
+	env = env_get("usb_pgood_delay");
 	if (env)
 		pgood_delay = max(pgood_delay,
 			          (unsigned)simple_strtol(env, NULL, 0));
diff --git a/common/usb_kbd.c b/common/usb_kbd.c
index d2d29cc..8cbdba6 100644
--- a/common/usb_kbd.c
+++ b/common/usb_kbd.c
@@ -515,7 +515,7 @@
 	if (error)
 		return error;
 
-	stdinname = getenv("stdin");
+	stdinname = env_get("stdin");
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
 	error = iomux_doenv(stdin, stdinname);
 	if (error)
@@ -582,7 +582,7 @@
 		if (stdio_deregister_dev(dev, force) != 0)
 			return 1;
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
-		if (iomux_doenv(stdin, getenv("stdin")) != 0)
+		if (iomux_doenv(stdin, env_get("stdin")) != 0)
 			return 1;
 #endif
 #ifdef CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE
@@ -627,7 +627,7 @@
 		goto err;
 	}
 #if CONFIG_IS_ENABLED(CONSOLE_MUX)
-	if (iomux_doenv(stdin, getenv("stdin"))) {
+	if (iomux_doenv(stdin, env_get("stdin"))) {
 		ret = -ENOLINK;
 		goto err;
 	}