From c6f06f22fca0776b343f419255df034809cb3fb9 Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 19 Jan 2016 21:21:59 +0000 Subject: MFC r291164, r291876, r292227: Print more detailed info about the disk and partition chosen for booting. No behavioral changes, just cosmetics. Remove stray unescaped `%` in `Booting from ...` informational message. Enhance the "ubenv import" command to allow importing a u-boot env var directly into a loader (and thus kernel) env var. --- sys/boot/uboot/common/main.c | 49 ++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'sys/boot/uboot/common/main.c') diff --git a/sys/boot/uboot/common/main.c b/sys/boot/uboot/common/main.c index b830354..bcbf6f1 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, ""); - if (currdev.d_disk.partition > 0) + if (currdev.d_disk.partition >= 0) sprintf(partition, "%d", currdev.d_disk.partition); else strcpy(partition, ""); @@ -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,41 @@ 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 (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 ldvar is malformed or there's no variable name left, punt. */ + if (ldvar[0] == 0 || var[0] == 0) + return; + val = ub_env_get(var); if (action == UBENV_SHOW) { if (val == NULL) @@ -592,8 +616,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); } } } -- cgit v1.1 From 73c42f454f020871f99f36350a399d27874a87c5 Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 19 Jan 2016 21:42:19 +0000 Subject: MFC r292888: Fix the error checking for the ubenv command. This moves the check for an empty ldvar (which amounts to the varname string starting with '=') into the if block that manipulates ldvar, which avoids later referencing ldvar when it was never initialized. --- sys/boot/uboot/common/main.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'sys/boot/uboot/common/main.c') diff --git a/sys/boot/uboot/common/main.c b/sys/boot/uboot/common/main.c index bcbf6f1..d860d97 100644 --- a/sys/boot/uboot/common/main.c +++ b/sys/boot/uboot/common/main.c @@ -585,6 +585,10 @@ handle_uboot_env_var(enum ubenv_action action, const char * var) */ 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); @@ -604,9 +608,11 @@ handle_uboot_env_var(enum ubenv_action action, const char * var) var = &var[6]; } - /* If ldvar is malformed or there's no variable name left, punt. */ - if (ldvar[0] == 0 || var[0] == 0) + /* 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) { -- cgit v1.1