summaryrefslogtreecommitdiffstats
path: root/sys/boot/uboot/common/main.c
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2016-01-25 08:56:15 -0200
committerRenato Botelho <renato@netgate.com>2016-01-25 08:56:15 -0200
commiteb84e0723f3b4bc5e40024f66fe21c14b09e9ec4 (patch)
treefec6b99d018e13f1fccbe31478aaf29a28a55642 /sys/boot/uboot/common/main.c
parentc50df8e1b90c4f9b8bbffa592477c129854776ce (diff)
parent94b1bbbd44bd88b6db1c00d795cdf7675b3ae254 (diff)
downloadFreeBSD-src-eb84e0723f3b4bc5e40024f66fe21c14b09e9ec4.zip
FreeBSD-src-eb84e0723f3b4bc5e40024f66fe21c14b09e9ec4.tar.gz
Merge remote-tracking branch 'origin/stable/10' into devel
Diffstat (limited to 'sys/boot/uboot/common/main.c')
-rw-r--r--sys/boot/uboot/common/main.c55
1 files changed, 42 insertions, 13 deletions
diff --git a/sys/boot/uboot/common/main.c b/sys/boot/uboot/common/main.c
index b830354..d860d97 100644
--- a/sys/boot/uboot/common/main.c
+++ b/sys/boot/uboot/common/main.c
@@ -315,7 +315,7 @@ print_disk_probe_info()
else
strcpy(slice, "<auto>");
- if (currdev.d_disk.partition > 0)
+ if (currdev.d_disk.partition >= 0)
sprintf(partition, "%d", currdev.d_disk.partition);
else
strcpy(partition, "<auto>");
@@ -382,7 +382,7 @@ probe_disks(int devidx, int load_type, int load_unit, int load_slice,
printf("\n");
}
- printf(" Requested disk type/unit not found\n");
+ printf(" Requested disk type/unit/slice/partition not found\n");
return (-1);
}
@@ -392,7 +392,7 @@ main(void)
struct api_signature *sig = NULL;
int load_type, load_unit, load_slice, load_partition;
int i;
- const char * loaderdev;
+ const char *ldev;
/*
* If we can't find the magic signature and related info, exit with a
@@ -485,10 +485,10 @@ main(void)
return (0xbadef1ce);
}
- env_setenv("currdev", EV_VOLATILE, uboot_fmtdev(&currdev),
- uboot_setcurrdev, env_nounset);
- env_setenv("loaddev", EV_VOLATILE, uboot_fmtdev(&currdev),
- env_noset, env_nounset);
+ ldev = uboot_fmtdev(&currdev);
+ env_setenv("currdev", EV_VOLATILE, ldev, uboot_setcurrdev, env_nounset);
+ env_setenv("loaddev", EV_VOLATILE, ldev, env_noset, env_nounset);
+ printf("Booting from %s\n", ldev);
setenv("LINES", "24", 1); /* optional */
setenv("prompt", "loader>", 1);
@@ -573,17 +573,47 @@ enum ubenv_action {
static void
handle_uboot_env_var(enum ubenv_action action, const char * var)
{
- const char * val;
- char ubv[128];
+ char ldvar[128];
+ const char *val;
+ char *wrk;
+ int len;
+
+ /*
+ * On an import with the variable name formatted as ldname=ubname,
+ * import the uboot variable ubname into the loader variable ldname,
+ * otherwise the historical behavior is to import to uboot.ubname.
+ */
+ if (action == UBENV_IMPORT) {
+ len = strcspn(var, "=");
+ if (len == 0) {
+ printf("name cannot start with '=': '%s'\n", var);
+ return;
+ }
+ if (var[len] == 0) {
+ strcpy(ldvar, "uboot.");
+ strncat(ldvar, var, sizeof(ldvar) - 7);
+ } else {
+ len = MIN(len, sizeof(ldvar) - 1);
+ strncpy(ldvar, var, len);
+ ldvar[len] = 0;
+ var = &var[len + 1];
+ }
+ }
/*
* 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;
+ var = &var[6];
}
+
+ /* If there is no variable name left, punt. */
+ if (var[0] == 0) {
+ printf("empty variable name\n");
+ return;
+ }
+
val = ub_env_get(var);
if (action == UBENV_SHOW) {
if (val == NULL)
@@ -592,8 +622,7 @@ handle_uboot_env_var(enum ubenv_action action, const char * var)
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);
+ setenv(ldvar, val, 1);
}
}
}
OpenPOWER on IntegriCloud