svn commit: r346497 - stable/12/stand/uboot/common

Ian Lepore ian at FreeBSD.org
Tue Sep 3 14:07:17 UTC 2019


Author: ian
Date: Sun Apr 21 20:46:49 2019
New Revision: 346497
URL: https://svnweb.freebsd.org/changeset/base/346497

Log:
  MFC r344260, r344335
  
  r344260:
  Allow the u-boot loaderdev env var to be formatted in the "usual" loader(8)
  way: device<unit>[s|p]<slice><partition>.  E.g., disk0s2a or disk3p12.
  The code first tries to parse the variable in this format using the
  standard disk_parsedev().  If that fails, it falls back to parsing the
  legacy format that has been supported by ubldr for years.
  
  In addition to 'disk', all the valid uboot device names can also be used:
  mmc, sata, usb, ide, scsi. The 'disk' device serves as an alias for all
  those types and will match the Nth storage-type device found (where N is
  the unit number).
  
  r344335:
  Fix the handling of legacy-format devices in the u-boot loaderdev variable.
  When I added support for the standard loader(8) disk0s2a: type formats,
  the parsing of legacy format was broken because it also contains a colon,
  but it comes before the slice and partition. That would cause disk_parsedev()
  to return success with the slice and partition set to wildcard values.
  
  This change examines the string first, and if it contains spaces, dots, or
  a colon at any position other than the end, it must be a legacy-format
  string and we don't even try to use disk_parsedev() on it.

Modified:
  stable/12/stand/uboot/common/main.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/stand/uboot/common/main.c
==============================================================================
--- stable/12/stand/uboot/common/main.c	Sun Apr 21 20:40:49 2019	(r346496)
+++ stable/12/stand/uboot/common/main.c	Sun Apr 21 20:46:49 2019	(r346497)
@@ -182,6 +182,14 @@ device_typename(int type)
  * The returned values for slice and partition are interpreted by
  * disk_open().
  *
+ * The device string can be a standard loader(8) disk specifier:
+ *
+ * disk<unit>s<slice>              disk0s1
+ * disk<unit>s<slice><partition>   disk1s2a
+ * disk<unit>p<partition>          disk0p4
+ *
+ * or one of the following formats:
+ *
  * Valid device strings:                     For device types:
  *
  * <type_name>                               DEV_TYP_STOR, DEV_TYP_NET
@@ -198,6 +206,7 @@ device_typename(int type)
 static void
 get_load_device(int *type, int *unit, int *slice, int *partition)
 {
+	struct disk_devdesc dev;
 	char *devstr;
 	const char *p;
 	char *endp;
@@ -215,6 +224,26 @@ get_load_device(int *type, int *unit, int *slice, int 
 	printf("U-Boot env: loaderdev='%s'\n", devstr);
 
 	p = get_device_type(devstr, type);
+
+	/*
+	 * If type is DEV_TYP_STOR we have a disk-like device.  If the remainder
+	 * of the string contains spaces, dots, or a colon in any location other
+	 * than the last char, it's legacy format.  Otherwise it might be
+	 * standard loader(8) format (e.g., disk0s2a or mmc1p12), so try to
+	 * parse the remainder of the string as such, and if it works, return
+	 * those results. Otherwise we'll fall through to the code that parses
+	 * the legacy format.
+	 */
+	if (*type & DEV_TYP_STOR) {
+		size_t len = strlen(p);
+		if (strcspn(p, " .") == len && strcspn(p, ":") >= len - 1 &&
+		    disk_parsedev(&dev, p, NULL) == 0) {
+			*unit = dev.dd.d_unit;
+			*slice = dev.d_slice;
+			*partition = dev.d_partition;
+			return;
+		}
+	}
 
 	/* Ignore optional spaces after the device name. */
 	while (*p == ' ')




More information about the svn-src-stable-12 mailing list