Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 19 Jan 2016 21:21:59 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r294341 - stable/10/sys/boot/uboot/common
Message-ID:  <201601192121.u0JLLx7e040802@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Tue Jan 19 21:21:59 2016
New Revision: 294341
URL: https://svnweb.freebsd.org/changeset/base/294341

Log:
  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.

Modified:
  stable/10/sys/boot/uboot/common/main.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/boot/uboot/common/main.c
==============================================================================
--- stable/10/sys/boot/uboot/common/main.c	Tue Jan 19 21:08:31 2016	(r294340)
+++ stable/10/sys/boot/uboot/common/main.c	Tue Jan 19 21:21:59 2016	(r294341)
@@ -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, i
 		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 a
 			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);
 		}
 	}
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201601192121.u0JLLx7e040802>