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).
This commit is contained in:
Ian Lepore 2019-02-18 17:12:30 +00:00
parent 8cbe929be5
commit 28ef0240e0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=344260

View file

@ -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;
@ -216,6 +225,19 @@ get_load_device(int *type, int *unit, int *slice, int *partition)
p = get_device_type(devstr, type);
/*
* If type is DEV_TYP_STOR we have a disk-like device. If we can parse
* the remainder of the string as a standard unit+slice+partition (e.g.,
* 0s2a or 1p12), return those results. Otherwise we'll fall through to
* the code that parses the legacy format.
*/
if ((*type & DEV_TYP_STOR) && 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 == ' ')
p++;