diff options
author | Simon Glass <sjg@chromium.org> | 2023-01-17 10:48:00 -0700 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2023-01-23 18:11:41 -0500 |
commit | 74ebfb60f6890ab46d5233d13941ff9d6eea2312 (patch) | |
tree | 6f415e41360d8ce1006e151a816484e8e1aa324e /boot | |
parent | a58e7bbeb64d8989bb6fc8699c84053e383361af (diff) | |
download | u-boot-74ebfb60f6890ab46d5233d13941ff9d6eea2312.tar.gz u-boot-74ebfb60f6890ab46d5233d13941ff9d6eea2312.tar.bz2 u-boot-74ebfb60f6890ab46d5233d13941ff9d6eea2312.zip |
bootstd: Move label parsing into its own function
This is complicated enough to merit its own function, particularly as we
are about to add to it. Create a new label_to_uclass() function to decode
a label.
Also update the code to ignore an empty label or one consisting of just a
number.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'boot')
-rw-r--r-- | boot/bootdev-uclass.c | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c index 3dcf317c15..f43307d006 100644 --- a/boot/bootdev-uclass.c +++ b/boot/bootdev-uclass.c @@ -355,6 +355,37 @@ int bootdev_unbind_dev(struct udevice *parent) } /** + * label_to_uclass() - Convert a label to a uclass and sequence number + * + * @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 + */ +static int label_to_uclass(const char *label, int *seqp) +{ + enum uclass_id id; + const char *end; + int seq, len; + + seq = trailing_strtoln_end(label, NULL, &end); + len = end - label; + if (!len) + return -EINVAL; + id = uclass_get_by_namelen(label, 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; + } + if (id == UCLASS_USB) + id = UCLASS_MASS_STORAGE; + *seqp = seq; + + 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 @@ -372,19 +403,12 @@ int bootdev_find_by_label(const char *label, struct udevice **devp) struct udevice *media; struct uclass *uc; enum uclass_id id; - const char *end; - int seq; + int seq, ret; - seq = trailing_strtoln_end(label, NULL, &end); - id = uclass_get_by_namelen(label, end - label); - 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; - } - if (id == UCLASS_USB) - id = UCLASS_MASS_STORAGE; + ret = label_to_uclass(label, &seq); + if (ret < 0) + return log_msg_ret("uc", ret); + id = ret; /* Iterate through devices in the media uclass (e.g. UCLASS_MMC) */ uclass_id_foreach_dev(id, media, uc) { |