int bootdev_find_in_blk(struct udevice *dev, struct udevice *blk,
struct bootflow_iter *iter, struct bootflow *bflow)
{
+ struct bootmeth_uc_plat *plat = dev_get_uclass_plat(bflow->method);
+ bool allow_any_part = plat->flags & BOOTMETHF_ANY_PART;
struct blk_desc *desc = dev_get_uclass_plat(blk);
struct disk_partition info;
char partstr[20];
* us whether there is valid media there
*/
ret = part_get_info(desc, iter->part, &info);
+ log_debug("part_get_info() returned %d\n", ret);
if (!iter->part && ret == -ENOENT)
ret = 0;
ret = -ESHUTDOWN;
else
bflow->state = BOOTFLOWST_MEDIA;
- if (ret)
+ if (ret && !allow_any_part) {
+ /* allow partition 1 to be missing */
+ if (iter->part == 1) {
+ iter->max_part = 3;
+ ret = -ENOENT;
+ }
+
return log_msg_ret("part", ret);
+ }
/*
* Currently we don't get the number of partitions, so just
if (!iter->part) {
iter->first_bootable = part_get_bootable(desc);
log_debug("checking bootable=%d\n", iter->first_bootable);
+ } else if (allow_any_part) {
+ /*
+ * allow any partition to be scanned, by skipping any checks
+ * for filesystems or partition contents on this disk
+ */
/* if there are bootable partitions, scan only those */
- } else if (iter->first_bootable ? !info.bootable : iter->part != 1) {
+ } else if (iter->first_bootable >= 0 &&
+ (iter->first_bootable ? !info.bootable : iter->part != 1)) {
return log_msg_ret("boot", -EINVAL);
} else {
ret = fs_set_blk_dev_with_part(desc, bflow->part);
bflow->state = BOOTFLOWST_PART;
+ if (ret)
+ return log_msg_ret("fs", ret);
- /* Use an #ifdef due to info.sys_ind */
-#ifdef CONFIG_DOS_PARTITION
log_debug("%s: Found partition %x type %x fstype %d\n",
- blk->name, bflow->part, info.sys_ind,
+ blk->name, bflow->part,
+ IS_ENABLED(CONFIG_DOS_PARTITION) ?
+ disk_partition_sys_ind(&info) : 0,
ret ? -1 : fs_get_type());
-#endif
- if (ret)
- return log_msg_ret("fs", ret);
+ bflow->blk = blk;
bflow->state = BOOTFLOWST_FS;
}
+ log_debug("method %s\n", bflow->method->name);
ret = bootmeth_read_bootflow(bflow->method, bflow);
if (ret)
return log_msg_ret("method", ret);
for (i = 0; dev; i++) {
printf("%3x [ %c ] %6s %-9.9s %s\n", dev_seq(dev),
device_active(dev) ? '+' : ' ',
- ret ? simple_itoa(ret) : "OK",
+ ret ? simple_itoa(-ret) : "OK",
dev_get_uclass_name(dev_get_parent(dev)), dev->name);
if (probe)
ret = uclass_next_device_check(&dev);
return len;
}
-int bootdev_setup_sibling_blk(struct udevice *blk, const char *drv_name)
+int bootdev_setup_for_sibling_blk(struct udevice *blk, const char *drv_name)
{
struct udevice *parent, *dev;
char dev_name[50];
if (device_get_uclass_id(dev) != UCLASS_BOOTDEV)
return -EINVAL;
- /* This should always work if bootdev_setup_sibling_blk() was used */
+ /*
+ * This should always work if bootdev_setup_for_sibling_blk() was used
+ */
len = bootdev_get_suffix_start(dev, ".bootdev");
ret = device_find_child_by_namelen(parent, dev->name, len, &blk);
if (ret) {
if (ret)
return log_msg_ret("find", ret);
}
+ ret = device_probe(blk);
+ if (ret)
+ return log_msg_ret("act", ret);
*blkp = blk;
return 0;
if (device_get_uclass_id(blk) != UCLASS_BLK)
return -EINVAL;
- /* This should always work if bootdev_setup_sibling_blk() was used */
+ /* This should always work if bootdev_setup_for_sibling_blk() was used */
len = bootdev_get_suffix_start(blk, ".blk");
snprintf(dev_name, sizeof(dev_name), "%.*s.%s", len, blk->name,
"bootdev");
*
* @label: Label to look up (e.g. "mmc1" or "mmc0")
* @seqp: Returns the sequence number, or -1 if none
- * Returns: sequence number on success, else -ve error code
+ * @method_flagsp: If non-NULL, returns any flags implied by the label
+ * (enum bootflow_meth_flags_t), 0 if none
+ * Returns: sequence number on success, -EPFNOSUPPORT is the uclass is not
+ * known, other -ve error code on other error
*/
-static int label_to_uclass(const char *label, int *seqp)
+static int label_to_uclass(const char *label, int *seqp, int *method_flagsp)
{
+ int seq, len, method_flags;
enum uclass_id id;
const char *end;
- int seq, len;
+ method_flags = 0;
seq = trailing_strtoln_end(label, NULL, &end);
len = end - label;
if (!len)
log_debug("find %s: seq=%d, id=%d/%s\n", label, seq, id,
uclass_get_name(id));
if (id == UCLASS_INVALID) {
- log_warning("Unknown uclass '%s' in label\n", label);
- return -EINVAL;
+ /* try some special cases */
+ if (IS_ENABLED(CONFIG_BOOTDEV_SPI_FLASH) &&
+ !strncmp("spi", label, len)) {
+ id = UCLASS_SPI_FLASH;
+ } else if (IS_ENABLED(CONFIG_BOOTDEV_ETH) &&
+ !strncmp("pxe", label, len)) {
+ id = UCLASS_ETH;
+ method_flags |= BOOTFLOW_METHF_PXE_ONLY;
+ } else if (IS_ENABLED(CONFIG_BOOTDEV_ETH) &&
+ !strncmp("dhcp", label, len)) {
+ id = UCLASS_ETH;
+ method_flags |= BOOTFLOW_METHF_DHCP_ONLY;
+ } else {
+ return -EPFNOSUPPORT;
+ }
}
if (id == UCLASS_USB)
id = UCLASS_MASS_STORAGE;
*seqp = seq;
+ if (method_flagsp)
+ *method_flagsp = method_flags;
return id;
}
-/**
- * bootdev_find_by_label() - Convert a label string to a bootdev device
- *
- * Looks up a label name to find the associated bootdev. For example, if the
- * label name is "mmc2", this will find a bootdev for an mmc device whose
- * sequence number is 2.
- *
- * @label: Label string to convert, e.g. "mmc2"
- * @devp: Returns bootdev device corresponding to that boot label
- * Return: 0 if OK, -EINVAL if the label name (e.g. "mmc") does not refer to a
- * uclass, -ENOENT if no bootdev for that media has the sequence number
- * (e.g. 2)
- */
-int bootdev_find_by_label(const char *label, struct udevice **devp)
+int bootdev_find_by_label(const char *label, struct udevice **devp,
+ int *method_flagsp)
{
+ int seq, ret, method_flags = 0;
struct udevice *media;
struct uclass *uc;
enum uclass_id id;
- int seq, ret;
- ret = label_to_uclass(label, &seq);
+ ret = label_to_uclass(label, &seq, &method_flags);
if (ret < 0)
return log_msg_ret("uc", ret);
id = ret;
if (!ret) {
log_debug("- found %s\n", bdev->name);
*devp = bdev;
+
+ /*
+ * if no sequence number was provided, we must scan all
+ * bootdevs for this media uclass
+ */
+ if (IS_ENABLED(CONFIG_BOOTSTD_FULL) && seq == -1)
+ method_flags |= BOOTFLOW_METHF_SINGLE_UCLASS;
+ if (method_flagsp)
+ *method_flagsp = method_flags;
return 0;
}
log_debug("- no device in %s\n", media->name);
}
- log_warning("Unknown seq %d for label '%s'\n", seq, label);
return -ENOENT;
}
-int bootdev_find_by_any(const char *name, struct udevice **devp)
+int bootdev_find_by_any(const char *name, struct udevice **devp,
+ int *method_flagsp)
{
struct udevice *dev;
- int ret, seq;
+ int method_flags = 0;
+ int ret = -ENODEV, seq;
char *endp;
seq = simple_strtol(name, &endp, 16);
if (*endp) {
ret = uclass_get_device_by_name(UCLASS_BOOTDEV, name, &dev);
if (ret == -ENODEV) {
- ret = bootdev_find_by_label(name, &dev);
+ ret = bootdev_find_by_label(name, &dev, &method_flags);
if (ret) {
printf("Cannot find bootdev '%s' (err=%d)\n",
name, ret);
- return ret;
+ return log_msg_ret("lab", ret);
}
ret = device_probe(dev);
}
if (ret) {
printf("Cannot probe bootdev '%s' (err=%d)\n", name,
ret);
- return ret;
+ return log_msg_ret("pro", ret);
}
- } else {
+ } else if (IS_ENABLED(CONFIG_BOOTSTD_FULL)) {
ret = uclass_get_device_by_seq(UCLASS_BOOTDEV, seq, &dev);
+ method_flags |= BOOTFLOW_METHF_SINGLE_DEV;
}
if (ret) {
printf("Cannot find '%s' (err=%d)\n", name, ret);
}
*devp = dev;
+ if (method_flagsp)
+ *method_flagsp = method_flags;
+
+ return 0;
+}
+
+int bootdev_hunt_and_find_by_label(const char *label, struct udevice **devp,
+ int *method_flagsp)
+{
+ int ret;
+
+ ret = bootdev_hunt(label, false);
+ if (ret)
+ return log_msg_ret("scn", ret);
+ ret = bootdev_find_by_label(label, devp, method_flagsp);
+ if (ret)
+ return log_msg_ret("fnd", ret);
return 0;
}
int ret;
ret = bootdev_get_sibling_blk(dev, &blk);
+ log_debug("sibling_blk ret=%d, blk=%s\n", ret,
+ ret ? "(none)" : blk->name);
/*
* If there is no media, indicate that no more partitions should be
* checked
{
const struct bootdev_ops *ops = bootdev_get_ops(dev);
+ log_debug("->get_bootflow %s,%x=%p\n", dev->name, iter->part,
+ ops->get_bootflow);
bootflow_init(bflow, dev, iter->method);
if (!ops->get_bootflow)
return default_get_bootflow(dev, iter, bflow);
}
}
-/**
- * h_cmp_bootdev() - Compare two bootdevs to find out which should go first
- *
- * @v1: struct udevice * of first bootdev device
- * @v2: struct udevice * of second bootdev device
- * Return: sort order (<0 if dev1 < dev2, ==0 if equal, >0 if dev1 > dev2)
- */
-static int h_cmp_bootdev(const void *v1, const void *v2)
+int bootdev_next_label(struct bootflow_iter *iter, struct udevice **devp,
+ int *method_flagsp)
{
- const struct udevice *dev1 = *(struct udevice **)v1;
- const struct udevice *dev2 = *(struct udevice **)v2;
- const struct bootdev_uc_plat *ucp1 = dev_get_uclass_plat(dev1);
- const struct bootdev_uc_plat *ucp2 = dev_get_uclass_plat(dev2);
- int diff;
+ struct udevice *dev;
- /* Use priority first */
- diff = ucp1->prio - ucp2->prio;
- if (diff)
- return diff;
+ log_debug("next\n");
+ for (dev = NULL; !dev && iter->labels[++iter->cur_label];) {
+ const char *label = iter->labels[iter->cur_label];
+ int ret;
- /* Fall back to seq for devices of the same priority */
- diff = dev_seq(dev1) - dev_seq(dev2);
+ log_debug("Scanning: %s\n", label);
+ ret = bootdev_hunt_and_find_by_label(label, &dev,
+ method_flagsp);
+ if (iter->flags & BOOTFLOWIF_SHOW) {
+ if (ret == -EPFNOSUPPORT) {
+ log_warning("Unknown uclass '%s' in label\n",
+ label);
+ } else if (ret == -ENOENT) {
+ /*
+ * looking for, e.g. 'scsi0' should find
+ * something if SCSI is present
+ */
+ if (!trailing_strtol(label)) {
+ log_warning("No bootdevs for '%s'\n",
+ label);
+ }
+ }
+ }
- return diff;
+ }
+
+ if (!dev)
+ return log_msg_ret("fin", -ENODEV);
+ *devp = dev;
+
+ return 0;
}
-/**
- * build_order() - Build the ordered list of bootdevs to use
- *
- * This builds an ordered list of devices by one of three methods:
- * - using the boot_targets environment variable, if non-empty
- * - using the bootdev-order devicetree property, if present
- * - sorted by priority and sequence number
- *
- * @bootstd: BOOTSTD device to use
- * @order: Bootdevs listed in default order
- * @max_count: Number of entries in @order
- * Return: number of bootdevs found in the ordering, or -E2BIG if the
- * boot_targets string is too long, or -EXDEV if the ordering produced 0 results
- */
-static int build_order(struct udevice *bootstd, struct udevice **order,
- int max_count)
+int bootdev_next_prio(struct bootflow_iter *iter, struct udevice **devp)
{
- const char *overflow_target = NULL;
- const char *const *labels;
- struct udevice *dev;
- int i, ret, count;
- bool ok;
-
- labels = bootstd_get_bootdev_order(bootstd, &ok);
- if (!ok)
- return log_msg_ret("ord", -ENOMEM);
- if (labels) {
- int upto;
-
- upto = 0;
- for (i = 0; labels[i]; i++) {
- ret = bootdev_find_by_label(labels[i], &dev);
- if (!ret) {
- if (upto == max_count) {
- overflow_target = labels[i];
- break;
- }
- order[upto++] = dev;
- }
+ struct udevice *dev = *devp;
+ bool found;
+ int ret;
+
+ /* find the next device with this priority */
+ *devp = NULL;
+ log_debug("next prio %d: dev=%p/%s\n", iter->cur_prio, dev,
+ dev ? dev->name : "none");
+ do {
+ /*
+ * Don't probe devices here since they may not be of the
+ * required priority
+ */
+ if (!dev)
+ uclass_find_first_device(UCLASS_BOOTDEV, &dev);
+ else
+ uclass_find_next_device(&dev);
+ found = false;
+
+ /* scan for the next device with the correct priority */
+ while (dev) {
+ struct bootdev_uc_plat *plat;
+
+ plat = dev_get_uclass_plat(dev);
+ log_debug("- %s: %d, want %d\n", dev->name, plat->prio,
+ iter->cur_prio);
+ if (plat->prio == iter->cur_prio)
+ break;
+ uclass_find_next_device(&dev);
}
- count = upto;
- } else {
- /* sort them into priority order */
- count = max_count;
- qsort(order, count, sizeof(struct udevice *), h_cmp_bootdev);
- }
- if (overflow_target) {
- log_warning("Expected at most %d bootdevs, but overflowed with boot_target '%s'\n",
- max_count, overflow_target);
- }
+ /* none found for this priority, so move to the next */
+ if (!dev) {
+ log_debug("None found at prio %d, moving to %d\n",
+ iter->cur_prio, iter->cur_prio + 1);
+ if (++iter->cur_prio == BOOTDEVP_COUNT)
+ return log_msg_ret("fin", -ENODEV);
+
+ if (iter->flags & BOOTFLOWIF_HUNT) {
+ /* hunt to find new bootdevs */
+ ret = bootdev_hunt_prio(iter->cur_prio,
+ iter->flags &
+ BOOTFLOWIF_SHOW);
+ log_debug("- bootdev_hunt_prio() ret %d\n",
+ ret);
+ if (ret)
+ return log_msg_ret("hun", ret);
+ }
+ } else {
+ ret = device_probe(dev);
+ if (ret) {
+ log_debug("Device '%s' failed to probe\n",
+ dev->name);
+ dev = NULL;
+ }
+ }
+ } while (!dev);
- if (!count)
- return log_msg_ret("targ", -EXDEV);
+ *devp = dev;
- return count;
+ return 0;
}
-int bootdev_setup_iter_order(struct bootflow_iter *iter, struct udevice **devp)
+int bootdev_setup_iter(struct bootflow_iter *iter, const char *label,
+ struct udevice **devp, int *method_flagsp)
{
- struct udevice *bootstd, *dev = *devp, **order;
- struct uclass *uc;
- int count, upto;
+ struct udevice *bootstd, *dev = NULL;
+ bool show = iter->flags & BOOTFLOWIF_SHOW;
+ int method_flags;
int ret;
ret = uclass_first_device_err(UCLASS_BOOTSTD, &bootstd);
return log_msg_ret("std", ret);
}
- /* Handle scanning a single device */
- if (dev) {
- iter->flags |= BOOTFLOWF_SINGLE_DEV;
- return 0;
+ /* hunt for any pre-scan devices */
+ if (iter->flags & BOOTFLOWIF_HUNT) {
+ ret = bootdev_hunt_prio(BOOTDEVP_1_PRE_SCAN, show);
+ log_debug("- bootdev_hunt_prio() ret %d\n", ret);
+ if (ret)
+ return log_msg_ret("pre", ret);
}
- count = uclass_id_count(UCLASS_BOOTDEV);
- if (!count)
- return log_msg_ret("count", -ENOENT);
-
- order = calloc(count, sizeof(struct udevice *));
- if (!order)
- return log_msg_ret("order", -ENOMEM);
-
- /* Get the list of bootdevs */
- uclass_id_foreach_dev(UCLASS_BOOTDEV, dev, uc)
- order[upto++] = dev;
- log_debug("Found %d bootdevs\n", count);
- if (upto != count)
- log_debug("Expected %d bootdevs, found %d using aliases\n",
- count, upto);
-
- ret = build_order(bootstd, order, upto);
- if (ret < 0) {
- free(order);
- return log_msg_ret("build", ret);
- }
+ /* Handle scanning a single device */
+ if (IS_ENABLED(CONFIG_BOOTSTD_FULL) && label) {
+ if (iter->flags & BOOTFLOWIF_HUNT) {
+ ret = bootdev_hunt(label, show);
+ if (ret)
+ return log_msg_ret("hun", ret);
+ }
+ ret = bootdev_find_by_any(label, &dev, &method_flags);
+ if (ret)
+ return log_msg_ret("lab", ret);
- iter->num_devs = ret;
- iter->dev_order = order;
- iter->cur_dev = 0;
+ log_debug("method_flags: %x\n", method_flags);
+ if (method_flags & BOOTFLOW_METHF_SINGLE_UCLASS)
+ iter->flags |= BOOTFLOWIF_SINGLE_UCLASS;
+ else if (method_flags & BOOTFLOW_METHF_SINGLE_DEV)
+ iter->flags |= BOOTFLOWIF_SINGLE_DEV;
+ else
+ iter->flags |= BOOTFLOWIF_SINGLE_MEDIA;
+ log_debug("Selected label: %s, flags %x\n", label, iter->flags);
+ } else {
+ bool ok;
+
+ /* This either returns a non-empty list or NULL */
+ iter->labels = bootstd_get_bootdev_order(bootstd, &ok);
+ if (!ok)
+ return log_msg_ret("ord", -ENOMEM);
+ log_debug("setup labels %p\n", iter->labels);
+ if (iter->labels) {
+ iter->cur_label = -1;
+ ret = bootdev_next_label(iter, &dev, &method_flags);
+ } else {
+ ret = bootdev_next_prio(iter, &dev);
+ method_flags = 0;
+ }
+ if (!dev)
+ return log_msg_ret("fin", -ENOENT);
+ log_debug("Selected bootdev: %s\n", dev->name);
+ }
- dev = *order;
ret = device_probe(dev);
if (ret)
return log_msg_ret("probe", ret);
+ if (method_flagsp)
+ *method_flagsp = method_flags;
*devp = dev;
return 0;
log_debug("Hunting with: %s\n", name);
if (info->hunt) {
ret = info->hunt(info, show);
+ log_debug(" - hunt result %d\n", ret);
if (ret)
return ret;
}
log_debug("looking at %.*s for %s\n",
(int)max(strlen(name), len), spec, name);
- if (spec && strncmp(spec, name, max(strlen(name), len)))
- continue;
+ if (spec && strncmp(spec, name, max(strlen(name), len))) {
+ if (info->uclass != UCLASS_ETH ||
+ (strcmp("dhcp", spec) && strcmp("pxe", spec)))
+ continue;
+ }
ret = bootdev_hunt_drv(info, i, show);
if (ret)
result = ret;
return result;
}
+int bootdev_hunt_prio(enum bootdev_prio_t prio, bool show)
+{
+ struct bootdev_hunter *start;
+ int n_ent, i;
+ int result;
+
+ start = ll_entry_start(struct bootdev_hunter, bootdev_hunter);
+ n_ent = ll_entry_count(struct bootdev_hunter, bootdev_hunter);
+ result = 0;
+
+ log_debug("Hunting for priority %d\n", prio);
+ for (i = 0; i < n_ent; i++) {
+ struct bootdev_hunter *info = start + i;
+ int ret;
+
+ if (prio != info->prio)
+ continue;
+ ret = bootdev_hunt_drv(info, i, show);
+ log_debug("bootdev_hunt_drv() return %d\n", ret);
+ if (ret && ret != -ENOENT)
+ result = ret;
+ }
+ log_debug("exit %d\n", result);
+
+ return result;
+}
+
void bootdev_list_hunters(struct bootstd_priv *std)
{
struct bootdev_hunter *orig, *start;