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>
This commit is contained in:
Simon Glass
2017-08-03 12:22:12 -06:00
committed by Tom Rini
parent fd1e959e91
commit 00caae6d47
213 changed files with 531 additions and 502 deletions

View File

@ -28,7 +28,7 @@ static void print_eth(int idx)
sprintf(name, "eth%iaddr", idx);
else
strcpy(name, "ethaddr");
val = getenv(name);
val = env_get(name);
if (!val)
val = "(not set)";
printf("%-12s= %s\n", name, val);
@ -51,7 +51,7 @@ static void print_eths(void)
} while (dev);
printf("current eth = %s\n", eth_get_name());
printf("ip_addr = %s\n", getenv("ipaddr"));
printf("ip_addr = %s\n", env_get("ipaddr"));
}
#endif
@ -141,7 +141,7 @@ static inline void print_eth_ip_addr(void)
#if defined(CONFIG_HAS_ETH5)
print_eth(5);
#endif
printf("IP addr = %s\n", getenv("ipaddr"));
printf("IP addr = %s\n", env_get("ipaddr"));
#endif
}

View File

@ -138,7 +138,7 @@ int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
{
const char *ep = getenv("autostart");
const char *ep = env_get("autostart");
if (ep && !strcmp(ep, "yes")) {
char *local_args[2];
@ -202,7 +202,7 @@ U_BOOT_CMD(
#if defined(CONFIG_CMD_BOOTD)
int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
return run_command(getenv("bootcmd"), flag);
return run_command(env_get("bootcmd"), flag);
}
U_BOOT_CMD(

View File

@ -53,7 +53,7 @@ static char *bootmenu_getoption(unsigned short int n)
return NULL;
sprintf(name, "bootmenu_%d", n);
return getenv(name);
return env_get(name);
}
static void bootmenu_print_entry(void *data)
@ -483,7 +483,7 @@ int do_bootmenu(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
delay_str = argv[1];
if (!delay_str)
delay_str = getenv("bootmenu_delay");
delay_str = env_get("bootmenu_delay");
if (delay_str)
delay = (int)simple_strtol(delay_str, NULL, 10);

View File

@ -104,7 +104,7 @@ int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
struct mtdids id;
ulong addr;
addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
addr = simple_strtoul(env_get("cramfsaddr"), NULL, 16);
/* hack! */
/* cramfs_* only supports NOR flash chips */
@ -117,9 +117,9 @@ int do_cramfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
part.offset = (u64)(uintptr_t) map_sysmem(addr - OFFSET_ADJUSTMENT, 0);
/* pre-set Boot file name */
if ((filename = getenv("bootfile")) == NULL) {
filename = env_get("bootfile");
if (!filename)
filename = "uImage";
}
if (argc == 2) {
filename = argv[1];
@ -169,7 +169,7 @@ int do_cramfs_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
struct mtdids id;
ulong addr;
addr = simple_strtoul(getenv("cramfsaddr"), NULL, 16);
addr = simple_strtoul(env_get("cramfsaddr"), NULL, 16);
/* hack! */
/* cramfs_* only supports NOR flash chips */

View File

@ -148,7 +148,7 @@ int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
unsigned long addr; /* Address of the ELF image */
unsigned long rc; /* Return value from user code */
char *sload = NULL;
const char *ep = getenv("autostart");
const char *ep = env_get("autostart");
int rcode = 0;
/* Consume 'bootelf' */
@ -258,7 +258,7 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
* (LOCAL_MEM_LOCAL_ADRS + BOOT_LINE_OFFSET) as defined by
* VxWorks BSP. For example, on PowerPC it defaults to 0x4200.
*/
tmp = getenv("bootaddr");
tmp = env_get("bootaddr");
if (!tmp) {
printf("## VxWorks bootline address not specified\n");
} else {
@ -269,21 +269,21 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
* parameter. If it is not defined, we may be able to
* construct the info.
*/
bootline = getenv("bootargs");
bootline = env_get("bootargs");
if (bootline) {
memcpy((void *)bootaddr, bootline,
max(strlen(bootline), (size_t)255));
flush_cache(bootaddr, max(strlen(bootline),
(size_t)255));
} else {
tmp = getenv("bootdev");
tmp = env_get("bootdev");
if (tmp) {
strcpy(build_buf, tmp);
ptr = strlen(tmp);
} else
printf("## VxWorks boot device not specified\n");
tmp = getenv("bootfile");
tmp = env_get("bootfile");
if (tmp)
ptr += sprintf(build_buf + ptr,
"host:%s ", tmp);
@ -295,10 +295,10 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
* The following parameters are only needed if 'bootdev'
* is an ethernet device, otherwise they are optional.
*/
tmp = getenv("ipaddr");
tmp = env_get("ipaddr");
if (tmp) {
ptr += sprintf(build_buf + ptr, "e=%s", tmp);
tmp = getenv("netmask");
tmp = env_get("netmask");
if (tmp) {
u32 mask = getenv_ip("netmask").s_addr;
ptr += sprintf(build_buf + ptr,
@ -308,19 +308,19 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
}
tmp = getenv("serverip");
tmp = env_get("serverip");
if (tmp)
ptr += sprintf(build_buf + ptr, "h=%s ", tmp);
tmp = getenv("gatewayip");
tmp = env_get("gatewayip");
if (tmp)
ptr += sprintf(build_buf + ptr, "g=%s ", tmp);
tmp = getenv("hostname");
tmp = env_get("hostname");
if (tmp)
ptr += sprintf(build_buf + ptr, "tn=%s ", tmp);
tmp = getenv("othbootargs");
tmp = env_get("othbootargs");
if (tmp) {
strcpy(build_buf + ptr, tmp);
ptr += strlen(tmp);
@ -341,12 +341,12 @@ int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
* Since E820 information is critical to the kernel, if we don't
* specify these in the environments, use a default one.
*/
tmp = getenv("e820data");
tmp = env_get("e820data");
if (tmp)
data = (struct e820entry *)simple_strtoul(tmp, NULL, 16);
else
data = (struct e820entry *)VXWORKS_E820_DATA_ADDR;
tmp = getenv("e820info");
tmp = env_get("e820info");
if (tmp)
info = (struct e820info *)simple_strtoul(tmp, NULL, 16);
else

View File

@ -43,8 +43,8 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
int op, dev = FPGA_INVALID_DEVICE;
size_t data_size = 0;
void *fpga_data = NULL;
char *devstr = getenv("fpga");
char *datastr = getenv("fpgadata");
char *devstr = env_get("fpga");
char *datastr = env_get("fpgadata");
int rc = FPGA_FAIL;
int wrong_parms = 0;
#if defined(CONFIG_FIT)

View File

@ -55,14 +55,14 @@ static int extract_env(const char *str, char **env)
memset(s + strlen(s) - 1, '\0', 1);
memmove(s, s + 2, strlen(s) - 1);
e = getenv(s);
e = env_get(s);
if (e == NULL) {
#ifdef CONFIG_RANDOM_UUID
debug("%s unset. ", str);
gen_rand_uuid_str(uuid_str, UUID_STR_FORMAT_GUID);
env_set(s, uuid_str);
e = getenv(s);
e = env_get(s);
if (e) {
debug("Set to random.\n");
ret = 0;

View File

@ -238,9 +238,9 @@ static int do_ini(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
section = argv[1];
file_address = (char *)simple_strtoul(
argc < 3 ? getenv("loadaddr") : argv[2], NULL, 16);
argc < 3 ? env_get("loadaddr") : argv[2], NULL, 16);
file_size = (size_t)simple_strtoul(
argc < 4 ? getenv("filesize") : argv[3], NULL, 16);
argc < 4 ? env_get("filesize") : argv[3], NULL, 16);
return ini_parse(file_address, file_size, ini_handler, (void *)section);
}

View File

@ -101,7 +101,7 @@ static char * evalstr(char *s)
i++;
}
s[i] = 0;
return getenv((const char *)&s[2]);
return env_get((const char *)&s[2]);
} else {
return s;
}

View File

@ -479,9 +479,9 @@ int do_jffs2_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
ulong offset = load_addr;
/* pre-set Boot file name */
if ((filename = getenv("bootfile")) == NULL) {
filename = env_get("bootfile");
if (!filename)
filename = "uImage";
}
if (argc == 2) {
filename = argv[1];

View File

@ -50,11 +50,11 @@ static int do_load_serial(cmd_tbl_t *cmdtp, int flag, int argc,
load_baudrate = current_baudrate = gd->baudrate;
#endif
if (((env_echo = getenv("loads_echo")) != NULL) && (*env_echo == '1')) {
env_echo = env_get("loads_echo");
if (env_echo && *env_echo == '1')
do_echo = 1;
} else {
else
do_echo = 0;
}
#ifdef CONFIG_SYS_LOADS_BAUD_CHANGE
if (argc >= 2) {
@ -427,9 +427,9 @@ static int do_load_serial_bin(cmd_tbl_t *cmdtp, int flag, int argc,
offset = CONFIG_SYS_LOAD_ADDR;
/* pre-set offset from $loadaddr */
if ((s = getenv("loadaddr")) != NULL) {
s = env_get("loadaddr");
if (s)
offset = simple_strtoul(s, NULL, 16);
}
load_baudrate = current_baudrate = gd->baudrate;

View File

@ -71,7 +71,8 @@ void logbuff_init_ptrs(void)
#endif
/* Set up log version */
if ((s = getenv ("logversion")) != NULL)
s = env_get("logversion");
if (s)
log_version = (int)simple_strtoul(s, NULL, 10);
if (log_version == 2)
@ -94,7 +95,8 @@ void logbuff_init_ptrs(void)
log->v2.start = log->v2.con;
/* Initialize default loglevel if present */
if ((s = getenv ("loglevel")) != NULL)
s = env_get("loglevel");
if (s)
console_loglevel = (int)simple_strtoul(s, NULL, 10);
gd->flags |= GD_FLG_LOGINIT;

View File

@ -54,7 +54,7 @@ static int parse_verify_sum(char *verify_str, u8 *vsum)
if (strlen(verify_str) == 32)
vsum_str = verify_str;
else {
vsum_str = getenv(verify_str);
vsum_str = env_get(verify_str);
if (vsum_str == NULL || strlen(vsum_str) != 32)
return 1;
}

View File

@ -1536,8 +1536,8 @@ static int spread_partitions(void)
static const char *getenv_mtdparts(char *buf)
{
if (gd->flags & GD_FLG_ENV_READY)
return getenv("mtdparts");
if (getenv_f("mtdparts", buf, MTDPARTS_MAXLEN) != -1)
return env_get("mtdparts");
if (env_get_f("mtdparts", buf, MTDPARTS_MAXLEN) != -1)
return buf;
return NULL;
}
@ -1741,9 +1741,9 @@ int mtdparts_init(void)
}
/* get variables */
ids = getenv("mtdids");
ids = env_get("mtdids");
parts = getenv_mtdparts(tmp_parts);
current_partition = getenv("partition");
current_partition = env_get("partition");
/* save it for later parsing, cannot rely on current partition pointer
* as 'partition' variable may be updated during init */
@ -1850,7 +1850,7 @@ int mtdparts_init(void)
current_mtd_partnum = pnum;
current_save();
}
} else if (getenv("partition") == NULL) {
} else if (env_get("partition") == NULL) {
debug("no partition variable set, setting...\n");
current_save();
}

View File

@ -98,7 +98,7 @@ static ulong get_load_addr(void)
const char *addr_str;
unsigned long addr;
addr_str = getenv("loadaddr");
addr_str = env_get("loadaddr");
if (addr_str)
addr = simple_strtoul(addr_str, NULL, 16);
else

View File

@ -383,7 +383,7 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
#else
int quiet = 0;
#endif
const char *quiet_str = getenv("quiet");
const char *quiet_str = env_get("quiet");
int dev = nand_curr_device;
int repeat = flag & CMD_FLAG_REPEAT;
@ -966,11 +966,11 @@ static int do_nandboot(cmd_tbl_t *cmdtp, int flag, int argc,
switch (argc) {
case 1:
addr = CONFIG_SYS_LOAD_ADDR;
boot_device = getenv("bootdevice");
boot_device = env_get("bootdevice");
break;
case 2:
addr = simple_strtoul(argv[1], NULL, 16);
boot_device = getenv("bootdevice");
boot_device = env_get("bootdevice");
break;
case 3:
addr = simple_strtoul(argv[1], NULL, 16);

View File

@ -181,7 +181,7 @@ static int netboot_common(enum proto_t proto, cmd_tbl_t *cmdtp, int argc,
ulong addr;
/* pre-set load_addr */
s = getenv("loadaddr");
s = env_get("loadaddr");
if (s != NULL)
load_addr = simple_strtoul(s, NULL, 16);
@ -344,7 +344,7 @@ int do_sntp(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
}
toff = getenv("timeoffset");
toff = env_get("timeoffset");
if (toff == NULL)
net_ntp_time_offset = 0;
else

View File

@ -333,7 +333,7 @@ ulong getenv_hex(const char *varname, ulong default_val)
ulong value;
char *endp;
s = getenv(varname);
s = env_get(varname);
if (s)
value = simple_strtoul(s, &endp, 16);
if (!s || endp == s)
@ -594,7 +594,7 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
return 1;
/* Set read buffer to initial value or empty sting */
init_val = getenv(argv[1]);
init_val = env_get(argv[1]);
if (init_val)
snprintf(buffer, CONFIG_SYS_CBSIZE, "%s", init_val);
else
@ -622,7 +622,7 @@ static int do_env_edit(cmd_tbl_t *cmdtp, int flag, int argc,
* return address of storage for that variable,
* or NULL if not found
*/
char *getenv(const char *name)
char *env_get(const char *name)
{
if (gd->flags & GD_FLG_ENV_READY) { /* after import into hashtable */
ENTRY e, *ep;
@ -637,7 +637,7 @@ char *getenv(const char *name)
}
/* restricted capabilities before import */
if (getenv_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
if (env_get_f(name, (char *)(gd->env_buf), sizeof(gd->env_buf)) > 0)
return (char *)(gd->env_buf);
return NULL;
@ -646,7 +646,7 @@ char *getenv(const char *name)
/*
* Look up variable from environment for restricted C runtime env.
*/
int getenv_f(const char *name, char *buf, unsigned len)
int env_get_f(const char *name, char *buf, unsigned len)
{
int i, nxt;
@ -693,10 +693,10 @@ int getenv_f(const char *name, char *buf, unsigned len)
ulong getenv_ulong(const char *name, int base, ulong default_val)
{
/*
* We can use getenv() here, even before relocation, since the
* We can use env_get() here, even before relocation, since the
* environment variable value is an integer and thus short.
*/
const char *str = getenv(name);
const char *str = env_get(name);
return str ? simple_strtoul(str, NULL, base) : default_val;
}

View File

@ -33,15 +33,15 @@ const char *pxe_default_paths[] = {
static bool is_pxe;
/*
* Like getenv, but prints an error if envvar isn't defined in the
* environment. It always returns what getenv does, so it can be used in
* place of getenv without changing error handling otherwise.
* Like env_get, but prints an error if envvar isn't defined in the
* environment. It always returns what env_get does, so it can be used in
* place of env_get without changing error handling otherwise.
*/
static char *from_env(const char *envvar)
{
char *ret;
ret = getenv(envvar);
ret = env_get(envvar);
if (!ret)
printf("missing environment variable: %s\n", envvar);
@ -649,9 +649,9 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
}
bootm_argv[2] = initrd_str;
strcpy(bootm_argv[2], getenv("ramdisk_addr_r"));
strcpy(bootm_argv[2], env_get("ramdisk_addr_r"));
strcat(bootm_argv[2], ":");
strcat(bootm_argv[2], getenv("filesize"));
strcat(bootm_argv[2], env_get("filesize"));
}
if (get_relfile_envaddr(cmdtp, label->kernel, "kernel_addr_r") < 0) {
@ -662,8 +662,8 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
if (label->ipappend & 0x1) {
sprintf(ip_str, " ip=%s:%s:%s:%s",
getenv("ipaddr"), getenv("serverip"),
getenv("gatewayip"), getenv("netmask"));
env_get("ipaddr"), env_get("serverip"),
env_get("gatewayip"), env_get("netmask"));
}
#ifdef CONFIG_CMD_NET
@ -699,7 +699,7 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
printf("append: %s\n", finalbootargs);
}
bootm_argv[1] = getenv("kernel_addr_r");
bootm_argv[1] = env_get("kernel_addr_r");
/*
* fdt usage is optional:
@ -714,7 +714,7 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
*
* Scenario 3: fdt blob is not available.
*/
bootm_argv[3] = getenv("fdt_addr_r");
bootm_argv[3] = env_get("fdt_addr_r");
/* if fdt label is defined then get fdt from server */
if (bootm_argv[3]) {
@ -726,7 +726,7 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
} else if (label->fdtdir) {
char *f1, *f2, *f3, *f4, *slash;
f1 = getenv("fdtfile");
f1 = env_get("fdtfile");
if (f1) {
f2 = "";
f3 = "";
@ -739,9 +739,9 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
* or the boot scripts should set $fdtfile
* before invoking "pxe" or "sysboot".
*/
f1 = getenv("soc");
f1 = env_get("soc");
f2 = "-";
f3 = getenv("board");
f3 = env_get("board");
f4 = ".dtb";
}
@ -781,7 +781,7 @@ static int label_boot(cmd_tbl_t *cmdtp, struct pxe_label *label)
}
if (!bootm_argv[3])
bootm_argv[3] = getenv("fdt_addr");
bootm_argv[3] = env_get("fdt_addr");
if (bootm_argv[3]) {
if (!bootm_argv[2])
@ -1671,7 +1671,7 @@ static int do_sysboot(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
}
if (argc < 6)
filename = getenv("bootfile");
filename = env_get("bootfile");
else {
filename = argv[5];
env_set("bootfile", filename);

View File

@ -123,7 +123,7 @@ static int qemu_fwcfg_do_load(cmd_tbl_t *cmdtp, int flag,
void *load_addr;
void *initrd_addr;
env = getenv("loadaddr");
env = env_get("loadaddr");
load_addr = env ?
(void *)simple_strtoul(env, NULL, 16) :
#ifdef CONFIG_LOADADDR
@ -132,7 +132,7 @@ static int qemu_fwcfg_do_load(cmd_tbl_t *cmdtp, int flag,
NULL;
#endif
env = getenv("ramdiskaddr");
env = env_get("ramdiskaddr");
initrd_addr = env ?
(void *)simple_strtoul(env, NULL, 16) :
#ifdef CONFIG_RAMDISK_ADDR

View File

@ -88,18 +88,18 @@ int do_reiserload (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
switch (argc) {
case 3:
addr_str = getenv("loadaddr");
addr_str = env_get("loadaddr");
if (addr_str != NULL) {
addr = simple_strtoul (addr_str, NULL, 16);
} else {
addr = CONFIG_SYS_LOAD_ADDR;
}
filename = getenv ("bootfile");
filename = env_get("bootfile");
count = 0;
break;
case 4:
addr = simple_strtoul (argv[3], NULL, 16);
filename = getenv ("bootfile");
filename = env_get("bootfile");
count = 0;
break;
case 5:

View File

@ -145,7 +145,7 @@ static int regex_sub(const char *name,
}
if (t == NULL) {
value = getenv(name);
value = env_get(name);
if (value == NULL) {
printf("## Error: variable \"%s\" not defined\n", name);

View File

@ -51,10 +51,10 @@ static int do_zfs_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
count = 0;
addr = simple_strtoul(argv[3], NULL, 16);
filename = getenv("bootfile");
filename = env_get("bootfile");
switch (argc) {
case 3:
addr_str = getenv("loadaddr");
addr_str = env_get("loadaddr");
if (addr_str != NULL)
addr = simple_strtoul(addr_str, NULL, 16);
else