The 'part number' command currently allows looking up a partition
index only by its name.

Extend the command to support looking up the partition index via its
partition UUID. Unlike names, UUIDs guarantee unique partition
identification, avoiding ambiguity.

The logic is updated to check if the provided string is a valid UUID
before falling back to a name-based search.

Signed-off-by: Dario Binacchi <[email protected]>
---

 cmd/part.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/cmd/part.c b/cmd/part.c
index 975a0a08a99d..a3f3febb6977 100644
--- a/cmd/part.c
+++ b/cmd/part.c
@@ -139,6 +139,10 @@ static int do_part_info(int argc, char *const argv[], enum 
cmd_part_info param)
                err = part_get_info(desc, part, &info);
                if (err)
                        return 1;
+       } else if (uuid_str_valid(argv[2])) {
+               part = part_get_info_by_uuid(desc, argv[2], &info);
+               if (part < 0)
+                       return 1;
        } else {
                part = part_get_info_by_name(desc, argv[2], &info);
                if (part < 0)
@@ -314,8 +318,8 @@ U_BOOT_CMD(
        "    - set environment variable to the size of the partition (in 
blocks)\n"
        "      part can be either partition number or partition name\n"
        "part number <interface> <dev> <part> <varname>\n"
-       "    - set environment variable to the partition number using the 
partition name\n"
-       "      part must be specified as partition name\n"
+       "    - set environment variable to the partition number using the 
partition UUID or name\n"
+       "      part must be specified as partition UUID or name\n"
        "part name <interface> <dev> <part> <varname>\n"
        "    - set environment variable to the partition name using the 
partition number\n"
        "      part must be specified as partition number\n"
-- 
2.43.0

Reply via email to