mirror of
https://xff.cz/git/u-boot/
synced 2025-09-02 09:12:08 +02:00
Add getenv_hex() to return an environment variable as hex
This conversion is required in a number of places in U-Boot. Add a standard function to provide this feature, so we avoid all the different variations in the way it is coded. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -315,6 +315,21 @@ int setenv_hex(const char *varname, ulong value)
|
|||||||
return setenv(varname, str);
|
return setenv(varname, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ulong getenv_hex(const char *varname, ulong default_val)
|
||||||
|
{
|
||||||
|
const char *s;
|
||||||
|
ulong value;
|
||||||
|
char *endp;
|
||||||
|
|
||||||
|
s = getenv(varname);
|
||||||
|
if (s)
|
||||||
|
value = simple_strtoul(s, &endp, 16);
|
||||||
|
if (!s || endp == s)
|
||||||
|
return default_val;
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef CONFIG_SPL_BUILD
|
#ifndef CONFIG_SPL_BUILD
|
||||||
static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
static int do_env_set(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
{
|
{
|
||||||
|
@@ -352,6 +352,19 @@ int envmatch (uchar *, int);
|
|||||||
char *getenv (const char *);
|
char *getenv (const char *);
|
||||||
int getenv_f (const char *name, char *buf, unsigned len);
|
int getenv_f (const char *name, char *buf, unsigned len);
|
||||||
ulong getenv_ulong(const char *name, int base, ulong default_val);
|
ulong getenv_ulong(const char *name, int base, ulong default_val);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getenv_hex() - Return an environment variable as a hex value
|
||||||
|
*
|
||||||
|
* Decode an environment as a hex number (it may or may not have a 0x
|
||||||
|
* prefix). If the environment variable cannot be found, or does not start
|
||||||
|
* with hex digits, the default value is returned.
|
||||||
|
*
|
||||||
|
* @varname: Variable to decode
|
||||||
|
* @default_val: Value to return on error
|
||||||
|
*/
|
||||||
|
ulong getenv_hex(const char *varname, ulong default_val);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read an environment variable as a boolean
|
* Read an environment variable as a boolean
|
||||||
* Return -1 if variable does not exist (default to true)
|
* Return -1 if variable does not exist (default to true)
|
||||||
|
Reference in New Issue
Block a user