mirror of
https://github.com/freebsd/freebsd-src
synced 2024-09-06 17:18:32 +00:00
Add a 'ubenv import' command to import environment variables from the
u-boot env into the loader(8) env (which also gets them into the kernel env). You can import selected variables or the whole environment. Each u-boot var=value becomes uboot.var=value in the loader env. You can also use 'ubenv show' to display uboot vars without importing them.
This commit is contained in:
parent
28c80a7dd8
commit
6966304042
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=271285
|
@ -1 +1,27 @@
|
|||
$FreeBSD$
|
||||
|
||||
###############################################################################
|
||||
# Tubenv DShow or import U-Boot environment variables
|
||||
|
||||
ubenv <import | show> [varname ...]
|
||||
|
||||
Display U-Boot environment variables, or import them into the
|
||||
loader environment (which makes them available in the kernel).
|
||||
|
||||
###############################################################################
|
||||
# Tubenv Simport DImport U-Boot env vars
|
||||
|
||||
ubenv import [varname ...]
|
||||
|
||||
If no variable names are specified, all U-Boot environment
|
||||
variables are imported. Each variable is prefixed with "uboot."
|
||||
to avoid any possible conflicts with loader or kernel variables.
|
||||
|
||||
###############################################################################
|
||||
# Tubenv Sshow DShow U-Boot env vars
|
||||
|
||||
ubenv show [varname ...]
|
||||
|
||||
If no variable names are specified, all U-Boot environment
|
||||
variables are shown.
|
||||
|
||||
|
|
|
@ -556,6 +556,75 @@ command_sysinfo(int argc, char *argv[])
|
|||
return (CMD_OK);
|
||||
}
|
||||
|
||||
enum ubenv_action {
|
||||
UBENV_UNKNOWN,
|
||||
UBENV_SHOW,
|
||||
UBENV_IMPORT
|
||||
};
|
||||
|
||||
static void
|
||||
handle_uboot_env_var(enum ubenv_action action, const char * var)
|
||||
{
|
||||
const char * val;
|
||||
char ubv[128];
|
||||
|
||||
/*
|
||||
* If the user prepended "uboot." (which is how they usually see these
|
||||
* names) strip it off as a convenience.
|
||||
*/
|
||||
if (strncmp(var, "uboot.", 6) == 0) {
|
||||
snprintf(ubv, sizeof(ubv), "%s", &var[6]);
|
||||
var = ubv;
|
||||
}
|
||||
val = ub_env_get(var);
|
||||
if (action == UBENV_SHOW) {
|
||||
if (val == NULL)
|
||||
printf("uboot.%s is not set\n", var);
|
||||
else
|
||||
printf("uboot.%s=%s\n", var, val);
|
||||
} else if (action == UBENV_IMPORT) {
|
||||
if (val != NULL) {
|
||||
snprintf(ubv, sizeof(ubv), "uboot.%s", var);
|
||||
setenv(ubv, val, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
command_ubenv(int argc, char *argv[])
|
||||
{
|
||||
enum ubenv_action action;
|
||||
const char *var;
|
||||
int i;
|
||||
|
||||
action = UBENV_UNKNOWN;
|
||||
if (argc > 1) {
|
||||
if (strcasecmp(argv[1], "import") == 0)
|
||||
action = UBENV_IMPORT;
|
||||
else if (strcasecmp(argv[1], "show") == 0)
|
||||
action = UBENV_SHOW;
|
||||
}
|
||||
if (action == UBENV_UNKNOWN) {
|
||||
command_errmsg = "usage: 'ubenv <import|show> [var ...]";
|
||||
return (CMD_ERROR);
|
||||
}
|
||||
|
||||
if (argc > 2) {
|
||||
for (i = 2; i < argc; i++)
|
||||
handle_uboot_env_var(action, argv[i]);
|
||||
} else {
|
||||
var = NULL;
|
||||
for (;;) {
|
||||
if ((var = ub_env_enum(var)) == NULL)
|
||||
break;
|
||||
handle_uboot_env_var(action, var);
|
||||
}
|
||||
}
|
||||
|
||||
return (CMD_OK);
|
||||
}
|
||||
COMMAND_SET(ubenv, "ubenv", "show or import U-Boot env vars", command_ubenv);
|
||||
|
||||
#ifdef LOADER_FDT_SUPPORT
|
||||
/*
|
||||
* Since proper fdt command handling function is defined in fdt_loader_cmd.c,
|
||||
|
|
Loading…
Reference in a new issue