Skip to contentSkip to conversation

Add partition type GUID support for environment

PATCH Superseded Balaji Selvanathan 5 participants 15 messages Apr 28 – Nov 18 SCSI

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Add partition type GUID support for environment

This series adds support for locating partitions using GPT partition type GUID instead of unique partition UUID. This enables the saveenv command to work with partitions identified by their type rather than unique identifiers, providing flexibility for systems where partition UUIDs may vary across devices but types remain constant.

Patch 1 adds part_get_info_by_type_guid() function support Patch 2 adds scsi_get_blk_by_type_guid() function support Patch 3 optimizes scsi_get_blk_by_uuid() function
Patch 4 corrects default value of ENV_SCSI_HW_PARTITION config Patch 5 adds partition type GUID support and choice-based selection Patch 6 refactors the env/scsi codes based on the
SCSI partition selection configs
Patch 7 enables partition type GUID configs for QCM6490/QCS9100/QCS615 Patch 8 adds unit test for the partition type GUID lookup functionality

---
Changes in v4:
- Create a seperate patch for scsi_get_blk_by_uuid optimization
- Create a seperate patch for correcting default value of
ENV_SCSI_HW_PARTITION config
- Update help section of ENV_IS_IN_SCSI config
- Add 'select PARTITION_TYPE_GUID' for ENV_SCSI_PART_USE_TYPE_GUID
so that its selected automatically
- In test code, add more asserts to confirm its a kernel partition
- Link to v3: https://lore.kernel.org/u-boot/[email protected]/

Changes in v3:
- Addressed minor corrections in Patch 1 in part_get_info_by_type_guid function
- Refactor env_scsi_get_part and env_scsi_load functions based
on the choice configs in Patch 3
- Add unit test for the partition type GUID lookup functionality in Patch 5
- Link to v2: https://lore.kernel.org/u-boot/[email protected]/

Changes in v2:
- Compute blk_find_max_devnum(UCLASS_SCSI) only once in scsi_get_blk_by_type_guid()
- Introduce a Kconfig choice config to select between UUID-based
and type GUID-based partition lookup methods.
- Enable above new config in qcom_qcs615_defconfig and qcm6490_defconfig
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/

---
Balaji Selvanathan (8):
disk: Add partition lookup by type GUID functionality
scsi: Add partition lookup by type GUID for SCSI devices
scsi: Optimize scsi_get_blk_by_uuid() loop iteration
env: scsi: Fix ENV_SCSI_HW_PARTITION default value type
env: scsi: Add partition type GUID support and choice-based selection
env: scsi: Implement partition type GUID lookup
configs: Enable partition type GUID for QCS9100/QCM6490/QCS615 boards
test: dm: Add partition type GUID lookup test

 configs/qcm6490_defconfig      |  4 +++
 configs/qcom_qcs615_defconfig  |  4 +++
 configs/qcom_qcs9100_defconfig |  3 +-
 disk/part.c                    | 37 ++++++++++++++++++++++
 drivers/scsi/scsi-uclass.c     | 28 +++++++++++++++--
 env/Kconfig                    | 70 +++++++++++++++++++++++++++++++++---------
 env/scsi.c                     | 43 +++++++++++++++-----------
 include/part.h                 | 21 +++++++++++++
 include/scsi.h                 | 11 +++++++
 test/dm/part.c                 | 49 +++++++++++++++++++++++++++++
 10 files changed, 234 insertions(+), 36 deletions(-)

---
base-commit: 4433253ecf2041f9362a763bb6cb79960921ac7e
change-id: 20260428-type-7dc867309086

Best regards,

Signature · 1 line
Balaji Selvanathan <[email protected]>
#1 lore raw

PATCH v4 1/8 disk: Add partition lookup by type GUID functionality

Introduce part_get_info_by_type_guid() function to enable partition lookup using partition type GUID. This complements the existing UUID lookup functionality and provides more flexible partition discovery mechanisms.

---
Changes in v4:
- No changes

Changes in v3:
- Addressed minor corrections in part_get_info_by_type_guid function

Changes in v2:
- No changes
---

---
 disk/part.c    | 37 +++++++++++++++++++++++++++++++++++++
 include/part.h | 21 +++++++++++++++++++++
 2 files changed, 58 insertions(+)
disk/part.c +37 -0
index 4923dc44593..4cb3204ac6e 100644
@@ -731,6 +731,43 @@ int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid,
 	return -ENOENT;
 }
 
+int part_get_info_by_type_guid(struct blk_desc *desc, const char *type_guid,
+			       struct disk_partition *info)
+{
+	struct part_driver *part_drv;
+	int ret;
+	int i;
+
+	if (!CONFIG_IS_ENABLED(PARTITION_TYPE_GUID))
+		return -ENOENT;
+
+	part_drv = part_driver_lookup_type(desc);
+	if (!part_drv)
+		return -ENOENT;
+
+	for (i = 1; i <= part_drv->max_entries; i++) {
+		ret = part_driver_get_info(part_drv, desc, i, info);
+		if (ret) {
+			/* -ENOSYS means no ->get_info method. */
+			if (ret == -ENOSYS)
+				return ret;
+			/*
+			 * Partition with this index can't be obtained, but
+			 * further partitions might be, so keep checking.
+			 */
+			continue;
+		}
+
+		if (!strncasecmp(type_guid, disk_partition_type_guid(info),
+				 UUID_STR_LEN)) {
+			/* matched */
+			return i;
+		}
+	}
+
+	return -ENOENT;
+}
+
 /**
  * Get partition info from device number and partition name.
  *
include/part.h +21 -0
index 15daacd7faa..32614bd085b 100644
@@ -327,6 +327,20 @@ int part_get_info_by_name(struct blk_desc *desc, const char *name,
 int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid,
 			  struct disk_partition *info);
 
+/**
+ * part_get_info_by_type_guid() - Search for a partition by type GUID
+ *                                among all available registered partitions
+ *
+ * @desc:	block device descriptor
+ * @type_guid:	the specified partition type GUID
+ * @info:	the disk partition info
+ *
+ * Return: the partition number on match (starting on 1), -ENOENT on no match,
+ * otherwise error
+ */
+int part_get_info_by_type_guid(struct blk_desc *desc, const char *type_guid,
+			       struct disk_partition *info);
+
 /**
  * part_get_info_by_dev_and_name_or_num() - Get partition info from dev number
  *					    and part name, or dev number and
@@ -404,6 +418,13 @@ static inline int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid,
 	return -ENOENT;
 }
 
+static inline int part_get_info_by_type_guid(struct blk_desc *desc,
+					     const char *type_guid,
+					     struct disk_partition *info)
+{
+	return -ENOENT;
+}
+
 static inline int
 part_get_info_by_dev_and_name_or_num(const char *dev_iface,
 				     const char *dev_part_str,
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v4 1/8] disk: Add partition lookup by type GUID functionality

Hi Balaji,

Quoted 28 lines · Balaji Selvanathan

Introduce part_get_info_by_type_guid() function to enable partition lookup using partition type GUID. This complements the existing UUID lookup functionality and provides more flexible partition discovery mechanisms.

---
Changes in v4:
- No changes

Changes in v3:
- Addressed minor corrections in part_get_info_by_type_guid function

Changes in v2:
- No changes
---

---
  disk/part.c    | 37 +++++++++++++++++++++++++++++++++++++
  include/part.h | 21 +++++++++++++++++++++
  2 files changed, 58 insertions(+)
disk/part.c +0 -0
index 4923dc44593..4cb3204ac6e 100644
@@ -731,6 +731,43 @@ int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid,
  	return -ENOENT;

disk/part.c int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid, · line 741

Quoted 10 lines
disk/part.c +8 -0
  }
 
+int part_get_info_by_type_guid(struct blk_desc *desc, const char *type_guid,
+			       struct disk_partition *info)
+{
+	struct part_driver *part_drv;
+	int ret;
+	int i;
+
+	if (!CONFIG_IS_ENABLED(PARTITION_TYPE_GUID))

We don't have an xPL symbols for PARTITION_TYPE_GUID so you need to use IS_ENABLED(CONFIG_...) here otherwise it won't work in xPL stages.

Or you need to add an xPL symbol for that (see PARTITION_UUIDS and SPL_PARTITION_UUIDS).

Cheers,
Quentin

#3 lore raw

Re: [PATCH v4 1/8] disk: Add partition lookup by type GUID functionality

Quoted 44 lines · Quentin Schulz

Hi Balaji,

Quoted 27 lines · Balaji Selvanathan

Introduce part_get_info_by_type_guid() function to enable partition lookup using partition type GUID. This complements the existing UUID lookup functionality and provides more flexible partition discovery mechanisms.

---
Changes in v4:
- No changes

Changes in v3:
- Addressed minor corrections in part_get_info_by_type_guid function

Changes in v2:
- No changes
---

---
  disk/part.c    | 37 +++++++++++++++++++++++++++++++++++++
  include/part.h | 21 +++++++++++++++++++++
  2 files changed, 58 insertions(+)
disk/part.c +0 -0
index 4923dc44593..4cb3204ac6e 100644

disk/part.c int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid, · line 740

Quoted 10 lines
disk/part.c +8 -0
@@ -731,6 +731,43 @@ int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid,
  	return -ENOENT;
  }
+int part_get_info_by_type_guid(struct blk_desc *desc, const char *type_guid,
+			       struct disk_partition *info)
+{
+	struct part_driver *part_drv;
+	int ret;
+	int i;
+
+	if (!CONFIG_IS_ENABLED(PARTITION_TYPE_GUID))

We don't have an xPL symbols for PARTITION_TYPE_GUID so you need to use IS_ENABLED(CONFIG_...) here otherwise it won't work in xPL stages.

Quoted 2 lines

Or you need to add an xPL symbol for that (see PARTITION_UUIDS and SPL_PARTITION_UUIDS).

Jumping back here as I see in v5 it was switched to IS_ENABLED(...). I believe the correct approach is CONFIG_IS_ENABLED(...) and introducing if needed, or just waiting for the need otherwise, the xPL variant. This is because I can see for size reasons xPL and full U-Boot not having the same environment notion (perhaps NOWHERE being set) and so we instead run in to the other type of compile problem here. Generally speaking using CONFIG_IS_ENABLED(FOO) and later adding the xPL symbols, for shared code, is better than IS_ENABLED(CONFIG_FOO) because we want/need that flexibility (there are counter examples, but they are the exception, ie we *must* be consistent from phase to phase or know what a previous phase has done/next will do).

Signature · 1 line
Tom
#4 lore raw

Re: [PATCH v4 1/8] disk: Add partition lookup by type GUID functionality

Hi Tom, Balaji,

Quoted 48 lines · Tom Rini
Quoted 44 lines · Quentin Schulz

Hi Balaji,

Quoted 27 lines · Balaji Selvanathan

Introduce part_get_info_by_type_guid() function to enable partition lookup using partition type GUID. This complements the existing UUID lookup functionality and provides more flexible partition discovery mechanisms.

---
Changes in v4:
- No changes

Changes in v3:
- Addressed minor corrections in part_get_info_by_type_guid function

Changes in v2:
- No changes
---

---
   disk/part.c    | 37 +++++++++++++++++++++++++++++++++++++
   include/part.h | 21 +++++++++++++++++++++
   2 files changed, 58 insertions(+)
disk/part.c +0 -0
index 4923dc44593..4cb3204ac6e 100644

disk/part.c int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid, · line 740

Quoted 10 lines
disk/part.c +8 -0
@@ -731,6 +731,43 @@ int part_get_info_by_uuid(struct blk_desc *desc, const char *uuid,
   	return -ENOENT;
   }
+int part_get_info_by_type_guid(struct blk_desc *desc, const char *type_guid,
+			       struct disk_partition *info)
+{
+	struct part_driver *part_drv;
+	int ret;
+	int i;
+
+	if (!CONFIG_IS_ENABLED(PARTITION_TYPE_GUID))

We don't have an xPL symbols for PARTITION_TYPE_GUID so you need to use IS_ENABLED(CONFIG_...) here otherwise it won't work in xPL stages.

Quoted 2 lines

Or you need to add an xPL symbol for that (see PARTITION_UUIDS and SPL_PARTITION_UUIDS).

Quoted 12 lines

Jumping back here as I see in v5 it was switched to IS_ENABLED(...). I believe the correct approach is CONFIG_IS_ENABLED(...) and introducing if needed, or just waiting for the need otherwise, the xPL variant. This is because I can see for size reasons xPL and full U-Boot not having the same environment notion (perhaps NOWHERE being set) and so we instead run in to the other type of compile problem here. Generally speaking using CONFIG_IS_ENABLED(FOO) and later adding the xPL symbols, for shared code, is better than IS_ENABLED(CONFIG_FOO) because we want/need that flexibility (there are counter examples, but they are the exception, ie we *must* be consistent from phase to phase or know what a previous phase has done/next will do).

I keep getting confused by symbols that currently do not have an xPL variant as to whether that's on purpose (it should apply to all phases) or whether it should be gated by another (xPL) variant to apply to specific phases.

Here, the fact we only build disk/part.c in xPL if we have CONFIG_$(PHASE)_PARTITIONS=y means I was wrong and we should indeed use CONFIG_IS_ENABLED() as suggested by Tom. My apologies.

Cheers,
Quentin

#5 lore raw

Re: [PATCH v4 1/8] disk: Add partition lookup by type GUID functionality

Hi Tom, Quentin,

Quoted 66 lines · Quentin Schulz

Hi Tom, Balaji,

Quoted 50 lines · Tom Rini
Quoted 46 lines · Quentin Schulz

Hi Balaji,

Quoted 29 lines · Balaji Selvanathan

Introduce part_get_info_by_type_guid() function to enable partition lookup using partition type GUID. This complements the existing UUID lookup functionality and provides more flexible partition discovery mechanisms.

---
Changes in v4:
- No changes

Changes in v3:
- Addressed minor corrections in part_get_info_by_type_guid function

Changes in v2:
- No changes
---
---
   disk/part.c    | 37 +++++++++++++++++++++++++++++++++++++ include/part.h | 21 +++++++++++++++++++++

   2 files changed, 58 insertions(+)
disk/part.c +0 -0
index 4923dc44593..4cb3204ac6e 100644
@@ -731,6 +731,43 @@ int part_get_info_by_uuid(struct blk_desc 
 *desc, const char *uuid,
        return -ENOENT;

disk/part.c int part_get_info_by_uuid(struct blk_desc · line 742

Quoted 10 lines
disk/part.c +8 -0
    }
+int part_get_info_by_type_guid(struct blk_desc *desc, const char 
 *type_guid,
+                   struct disk_partition *info)
+{
+    struct part_driver *part_drv;
+    int ret;
+    int i;
+
+    if (!CONFIG_IS_ENABLED(PARTITION_TYPE_GUID))

We don't have an xPL symbols for PARTITION_TYPE_GUID so you need to use IS_ENABLED(CONFIG_...) here otherwise it won't work in xPL stages.

Quoted 2 lines

Or you need to add an xPL symbol for that (see PARTITION_UUIDS and SPL_PARTITION_UUIDS).

Quoted 12 lines

Jumping back here as I see in v5 it was switched to IS_ENABLED(...). I believe the correct approach is CONFIG_IS_ENABLED(...) and introducing if needed, or just waiting for the need otherwise, the xPL variant. This is because I can see for size reasons xPL and full U-Boot not having the same environment notion (perhaps NOWHERE being set) and so we instead run in to the other type of compile problem here. Generally speaking using CONFIG_IS_ENABLED(FOO) and later adding the xPL symbols, for shared code, is better than IS_ENABLED(CONFIG_FOO) because we want/need that flexibility (there are counter examples, but they are the exception, ie we *must* be consistent from phase to phase or know what a previous phase has done/next will do).

Quoted 3 lines

I keep getting confused by symbols that currently do not have an xPL variant as to whether that's on purpose (it should apply to all phases) or whether it should be gated by another (xPL) variant to apply to specific phases.

Here, the fact we only build disk/part.c in xPL if we have CONFIG_$(PHASE)_PARTITIONS=y means I was wrong and we should indeed use CONFIG_IS_ENABLED() as suggested by Tom. My apologies.

Noticed that SPL_PARTITION_TYPE_GUID already exists in disk/Kconfig; So will switch to CONFIG_IS_ENABLED(PARTITION_TYPE_GUID) in v6.

Thanks,

Balaji

Quoted 3 lines

Cheers,
Quentin

#6 lore raw

PATCH v4 2/8 scsi: Add partition lookup by type GUID for SCSI devices

In reply to Balaji Selvanathan

Introduce scsi_get_blk_by_type_guid() function to enable SCSI partition discovery using partition type GUID. This function scans all available SCSI devices and searches for a partition matching the specified type GUID.

---
Changes in v4:
- Kept only scsi_get_blk_by_type_guid related changes
- Removed scsi_get_blk_by_uuid changes

Changes in v3:
- No changes

Changes in v2:
- Compute blk_find_max_devnum(UCLASS_SCSI) only once in scsi_get_blk_by_type_guid()

---
 drivers/scsi/scsi-uclass.c | 23 +++++++++++++++++++++++
 include/scsi.h             | 11 +++++++++++
 2 files changed, 34 insertions(+)
drivers/scsi/scsi-uclass.c +23 -0
index 39b4c7476d4..cea6d771f7c 100644
@@ -47,6 +47,29 @@ int scsi_get_blk_by_uuid(const char *uuid,
 	return -ENODEV;
 }
 
+int scsi_get_blk_by_type_guid(const char *type_guid,
+			      struct blk_desc **blk_desc_ptr,
+			      struct disk_partition *part_info_ptr)
+{
+	struct blk_desc *blk;
+	int i, ret, max;
+
+	max = blk_find_max_devnum(UCLASS_SCSI) + 1;
+	for (i = 0; i < max; i++) {
+		ret = blk_get_desc(UCLASS_SCSI, i, &blk);
+		if (ret)
+			continue;
+
+		ret = part_get_info_by_type_guid(blk, type_guid, part_info_ptr);
+		if (ret > 0) {
+			*blk_desc_ptr = blk;
+			return 0;
+		}
+	}
+
+	return -ENODEV;
+}
+
 int scsi_bus_reset(struct udevice *dev)
 {
 	struct scsi_ops *ops = scsi_get_ops(dev);
include/scsi.h +11 -0
index 2520a8b8fe6..83aaf0a70f6 100644
@@ -366,6 +366,17 @@ int scsi_scan_dev(struct udevice *dev, bool verbose);
 int scsi_get_blk_by_uuid(const char *uuid, struct blk_desc **blk_desc_ptr,
 			 struct disk_partition *part_info_ptr);
 
+/**
+ * scsi_get_blk_by_type_guid() - Provides SCSI partition information by type GUID.
+ *
+ * @type_guid:		Type GUID of the partition for fetching its info
+ * @blk_desc_ptr:	Provides the blk descriptor
+ * @part_info_ptr:	Provides partition info
+ * Return: 0 if OK, -ve on error
+ */
+int scsi_get_blk_by_type_guid(const char *type_guid, struct blk_desc **blk_desc_ptr,
+			      struct disk_partition *part_info_ptr);
+
 #define SCSI_IDENTIFY					0xC0  /* not used */
 
 /* Hardware errors  */
Signature · 1 line
2.34.1
Reviewed-by on v4 2/8
#7 lore raw

Re: [PATCH v4 2/8] scsi: Add partition lookup by type GUID for SCSI devices

Hi Balaji,

Quoted 16 lines · Balaji Selvanathan

scsi: Add partition lookup by type GUID for SCSI devices

Introduce scsi_get_blk_by_type_guid() function to enable SCSI partition discovery using partition type GUID. This function scans all available SCSI devices and searches for a partition matching the specified type GUID.

drivers/scsi/scsi-uclass.c | 23 +++++++++++++++++++++++

 include/scsi.h             | 11 +++++++++++
 2 files changed, 34 insertions(+)

drivers/scsi/scsi-uclass.c int scsi_get_blk_by_uuid(const char *uuid, · line 47

Quoted 1 line
drivers/scsi/scsi-uclass.c +1 -0
@@ -47,6 +47,29 @@ int scsi_get_blk_by_uuid(const char *uuid,
+     Reviewed-by: Simon Glass <[email protected]>
#8 lore raw

PATCH v4 3/8 scsi: Optimize scsi_get_blk_by_uuid() loop iteration

In reply to Balaji Selvanathan

Compute blk_find_max_devnum(UCLASS_SCSI) only once instead of on every loop iteration for better performance.

---
Changes in v4:
- Newly created in v4
- Has only scsi_get_blk_by_uuid changes

---
 drivers/scsi/scsi-uclass.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/scsi/scsi-uclass.c +3 -2
index cea6d771f7c..031dc01b9de 100644
@@ -30,9 +30,10 @@ int scsi_get_blk_by_uuid(const char *uuid,
 			 struct disk_partition *part_info_ptr)
 {
 	struct blk_desc *blk;
-	int i, ret;
+	int i, ret, max;
 
-	for (i = 0; i < blk_find_max_devnum(UCLASS_SCSI) + 1; i++) {
+	max = blk_find_max_devnum(UCLASS_SCSI) + 1;
+	for (i = 0; i < max; i++) {
 		ret = blk_get_desc(UCLASS_SCSI, i, &blk);
 		if (ret)
 			continue;
Signature · 1 line
2.34.1
#9 lore raw

PATCH v4 4/8 env: scsi: Fix ENV_SCSI_HW_PARTITION default value type

In reply to Balaji Selvanathan

Change the default value from integer 0 to string "0" to match the string type of the configuration option.

---
Changes in v4:
- Newly created in v4

---
 env/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
env/Kconfig +1 -1
index 7abd82ab6f3..71a27894f90 100644
@@ -783,7 +783,7 @@ config ENV_MMC_USE_DT
 config ENV_SCSI_HW_PARTITION
 	string "SCSI hardware partition number"
 	depends on ENV_IS_IN_SCSI
-	default 0
+	default "0"
 	help
 	  SCSI hardware partition device number on the platform where the
 	  environment is stored.  Note that this is not related to any software
Signature · 1 line
2.34.1
#10 lore raw

PATCH v4 5/8 env: scsi: Add partition type GUID support and choice-based selection

In reply to Balaji Selvanathan

Add support for locating SCSI environment partition using GPT type GUID.

Introduce a Kconfig choice statement to select between three mutually exclusive partition lookup methods: UUID-based (default), type GUID-based, and hardware partition number.

Reorganize existing configs to depend on their respective choice options. Update ENV_IS_IN_SCSI help text to document the new configuration structure.

---
Changes in v4:
- Has only changes related to introducing choice configs

Changes in v3:
- Introduce a new choice config: ENV_SCSI_PART_USE_HW for ENV_SCSI_HW_PARTITION
- Refactor env_scsi_get_part and env_scsi_load functions based on the choice configs

Changes in v2:
- Introduce a Kconfig choice config to select between UUID-based and type GUID-based partition lookup methods.

---
 env/Kconfig | 68 ++++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 54 insertions(+), 14 deletions(-)
env/Kconfig +54 -14
index 71a27894f90..f59b2acb7e6 100644
@@ -299,16 +299,20 @@ config ENV_IS_IN_SCSI
 	  The size of the partition where the environment is stored in bytes. Must
 	  be a multiple of the partition block size.
 
-	  - CONFIG_ENV_SCSI_HW_PARTITION:
+	  The partition selection method is configured via a choice statement:
 
-	  Specifies which SCSI partition the environment is stored in. If not
-	  set, defaults to partition 0, the user area. Common values might be
-	  1 (first SCSI boot partition), 2 (second SCSI boot partition). Ignored
-	  if CONFIG_ENV_SCSI_PART_UUID is set to non-empty string.
+	  - ENV_SCSI_PART_USE_UUID: Use the partition's unique UUID to identify
+	    the SCSI partition for environment storage.
 
-	  - CONFIG_ENV_SCSI_PART_UUID:
+	  - ENV_SCSI_PART_USE_TYPE_GUID: Use the partition type GUID to identify
+	    the SCSI partition for environment storage. The first partition
+	    matching the specified type GUID will be used.
 
-	  UUID of the SCSI partition where the environment is stored.
+	  - ENV_SCSI_PART_USE_HW: Use the hardware device number to identify
+	    the SCSI device for environment storage. Specifies which SCSI
+	    partition the environment is stored in. If not set, defaults to
+	    partition 0, the user area. Common values might be 1 (first SCSI
+	    boot partition), 2 (second SCSI boot partition).
 
 
 config ENV_RANGE
@@ -780,9 +784,51 @@ config ENV_MMC_USE_DT
 	  The 2 defines CONFIG_ENV_OFFSET, CONFIG_ENV_OFFSET_REDUND
 	  are not used as fallback.
 
+choice
+	prompt "SCSI partition selection method"
+	depends on ENV_IS_IN_SCSI
+	default ENV_SCSI_PART_USE_UUID
+	help
+	  Select the method to identify the SCSI partition for environment storage.
+
+config ENV_SCSI_PART_USE_UUID
+	bool "Use partition UUID"
+	help
+	  Use the partition's unique UUID to identify the SCSI partition
+	  for environment storage.
+
+config ENV_SCSI_PART_USE_TYPE_GUID
+	bool "Use partition type GUID"
+	select PARTITION_TYPE_GUID
+	help
+	  Use the partition type GUID to identify the SCSI partition
+	  for environment storage. The first partition matching the
+	  specified type GUID will be used.
+
+config ENV_SCSI_PART_USE_HW
+	bool "Use hardware partition number"
+	help
+	  Use the hardware device number to identify the SCSI device
+	  for environment storage.
+
+endchoice
+
+config ENV_SCSI_PART_UUID
+	string "SCSI partition UUID for saving environment"
+	depends on ENV_SCSI_PART_USE_UUID
+	help
+	  UUID of the SCSI partition that you want to store the environment in.
+
+config ENV_SCSI_PART_TYPE_GUID
+	string "SCSI partition type GUID for saving environment"
+	depends on ENV_SCSI_PART_USE_TYPE_GUID
+	help
+	  Type GUID of the SCSI partition to store the environment in.
+	  Uses the first partition matching this type GUID.
+
 config ENV_SCSI_HW_PARTITION
 	string "SCSI hardware partition number"
-	depends on ENV_IS_IN_SCSI
+	depends on ENV_SCSI_PART_USE_HW
 	default "0"
 	help
 	  SCSI hardware partition device number on the platform where the
@@ -791,12 +837,6 @@ config ENV_SCSI_HW_PARTITION
 	  partition 0 or the first boot partition, which is 1 or some other defined
 	  partition.
 
-config ENV_SCSI_PART_UUID
-	string "SCSI partition UUID for saving environment"
-	depends on ENV_IS_IN_SCSI
-	help
-	  UUID of the SCSI partition that you want to store the environment in.
-
 config ENV_USE_DEFAULT_ENV_TEXT_FILE
 	bool "Create default environment from file"
 	depends on !COMPILE_TEST
Signature · 1 line
2.34.1
#11 lore raw

PATCH v4 6/8 env: scsi: Implement partition type GUID lookup

In reply to Balaji Selvanathan

Update env/scsi.c to support the new partition selection methods introduced in the Kconfig. Replace runtime string checks with compile-time preprocessor conditionals.

Implement support for all three partition selection methods:
- TYPE_GUID: Uses scsi_get_blk_by_type_guid()
- UUID: Uses scsi_get_blk_by_uuid()
- HW: Uses blk_get_device_part_str()

---
Changes in v4:
- Has only changes related to Refactor env_scsi_get_part and env_scsi_load functions based on the choice configs

Changes in v3:
- Introduce a new choice config: ENV_SCSI_PART_USE_HW for ENV_SCSI_HW_PARTITION
- Refactor env_scsi_get_part and env_scsi_load functions based on the choice configs

Changes in v2:
- Introduce a Kconfig choice config to select between UUID-based and type GUID-based partition lookup methods.

---
 env/scsi.c | 43 +++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)
env/scsi.c +25 -18
index 91a6c430302..b170f4ee0c7 100644
@@ -41,14 +41,17 @@ static inline struct env_scsi_info *env_scsi_get_part(void)
 		is_scsi_scanned = true;
 	}
 
-	if (CONFIG_ENV_SCSI_PART_UUID[0] == '\0') {
-		if (blk_get_device_part_str("scsi", CONFIG_ENV_SCSI_HW_PARTITION,
-					    &ep->blk, &ep->part, true))
-			return NULL;
-	} else {
-		if (scsi_get_blk_by_uuid(CONFIG_ENV_SCSI_PART_UUID, &ep->blk, &ep->part))
-			return NULL;
-	}
+#if defined(CONFIG_ENV_SCSI_PART_USE_TYPE_GUID)
+	if (scsi_get_blk_by_type_guid(CONFIG_ENV_SCSI_PART_TYPE_GUID, &ep->blk, &ep->part))
+		return NULL;
+#elif defined(CONFIG_ENV_SCSI_PART_USE_UUID)
+	if (scsi_get_blk_by_uuid(CONFIG_ENV_SCSI_PART_UUID, &ep->blk, &ep->part))
+		return NULL;
+#elif defined(CONFIG_ENV_SCSI_PART_USE_HW)
+	if (blk_get_device_part_str("scsi", CONFIG_ENV_SCSI_HW_PARTITION,
+				    &ep->blk, &ep->part, true))
+		return NULL;
+#endif
 
 	ep->count = CONFIG_ENV_SIZE / ep->part.blksz;
 
@@ -95,20 +98,24 @@ static int env_scsi_load(void)
 	int ret;
 
 	if (!ep) {
-		if (CONFIG_ENV_SCSI_PART_UUID[0] == '\0')
-			env_set_default("SCSI partition " CONFIG_ENV_SCSI_HW_PARTITION " not found", 0);
-		else
-			env_set_default(CONFIG_ENV_SCSI_PART_UUID " partition not found", 0);
-
+#if defined(CONFIG_ENV_SCSI_PART_USE_TYPE_GUID)
+		env_set_default("partition type " CONFIG_ENV_SCSI_PART_TYPE_GUID " not found", 0);
+#elif defined(CONFIG_ENV_SCSI_PART_USE_UUID)
+		env_set_default(CONFIG_ENV_SCSI_PART_UUID " partition not found", 0);
+#elif defined(CONFIG_ENV_SCSI_PART_USE_HW)
+		env_set_default("SCSI partition " CONFIG_ENV_SCSI_HW_PARTITION " not found", 0);
+#endif
 		return -ENOENT;
 	}
 
 	if (blk_dread(ep->blk, ep->part.start, ep->count, &envbuf) != ep->count) {
-		if (CONFIG_ENV_SCSI_PART_UUID[0] == '\0')
-			env_set_default("SCSI partition " CONFIG_ENV_SCSI_HW_PARTITION " read failed", 0);
-		else
-			env_set_default(CONFIG_ENV_SCSI_PART_UUID " partition read failed", 0);
-
+#if defined(CONFIG_ENV_SCSI_PART_USE_TYPE_GUID)
+		env_set_default("partition type " CONFIG_ENV_SCSI_PART_TYPE_GUID " read failed", 0);
+#elif defined(CONFIG_ENV_SCSI_PART_USE_UUID)
+		env_set_default(CONFIG_ENV_SCSI_PART_UUID " partition read failed", 0);
+#elif defined(CONFIG_ENV_SCSI_PART_USE_HW)
+		env_set_default("SCSI partition " CONFIG_ENV_SCSI_HW_PARTITION " read failed", 0);
+#endif
 		return -EIO;
 	}
 
Signature · 1 line
2.34.1
#12 lore raw

PATCH v4 7/8 configs: Enable partition type GUID for QCS9100/QCM6490/QCS615 boards

In reply to Balaji Selvanathan

Enable CONFIG_PARTITION_TYPE_GUID and configure SCSI environment partition type GUID for QCS9100, QCM6490 and QCS615 configurations. This allows these platforms to locate the environment partition using GPT type GUID instead of UUID.

---
Changes in v4:
- Add type guid configs to QCS9100 defconfig

Changes in v3:
- No changes

Changes in v2:
- Enable above new config in qcom_qcs615_defconfig and qcm6490_defconfig

---
 configs/qcm6490_defconfig      | 4 ++++
 configs/qcom_qcs615_defconfig  | 4 ++++
 configs/qcom_qcs9100_defconfig | 3 ++-
 3 files changed, 10 insertions(+), 1 deletion(-)
configs/qcm6490_defconfig +4 -0
index b088367f86c..9560886a37a 100644
@@ -16,3 +16,7 @@ CONFIG_DEFAULT_DEVICE_TREE="qcom/qcs6490-rb3gen2"
 
 CONFIG_FASTBOOT_BUF_ADDR=0xd8800000
 CONFIG_PHY_QCOM_QMP_COMBO=y
+
+CONFIG_ENV_IS_IN_SCSI=y
+CONFIG_ENV_SCSI_PART_USE_TYPE_GUID=y
+CONFIG_ENV_SCSI_PART_TYPE_GUID="bc0330eb-3410-4951-a617-03898dbe3372"
configs/qcom_qcs615_defconfig +4 -0
index 27666a8129d..d0ffa567619 100644
@@ -22,3 +22,7 @@ CONFIG_REMAKE_ELF=y
 CONFIG_TEXT_BASE=0x9fc00000
 
 CONFIG_FASTBOOT_BUF_ADDR=0xa1600000
+
+CONFIG_ENV_IS_IN_SCSI=y
+CONFIG_ENV_SCSI_PART_USE_TYPE_GUID=y
+CONFIG_ENV_SCSI_PART_TYPE_GUID="bc0330eb-3410-4951-a617-03898dbe3372"
configs/qcom_qcs9100_defconfig +2 -1
index 082106157bb..fbaf21952f2 100644
@@ -11,6 +11,7 @@ CONFIG_REMAKE_ELF=y
 CONFIG_FASTBOOT_BUF_ADDR=0xdb300000
 CONFIG_DEFAULT_DEVICE_TREE="qcom/qcs9100-ride-r3"
 CONFIG_ENV_IS_IN_SCSI=y
-CONFIG_ENV_SCSI_PART_UUID="71cb9cd0-acf1-b6cb-ad91-be9572fe11a9"
+CONFIG_ENV_SCSI_PART_USE_TYPE_GUID=y
+CONFIG_ENV_SCSI_PART_TYPE_GUID="bc0330eb-3410-4951-a617-03898dbe3372"
 # CONFIG_ENV_IS_DEFAULT is not set
 # CONFIG_ENV_IS_NOWHERE is not set
Signature · 1 line
2.34.1
#13 lore raw

Re: [PATCH v4 7/8] configs: Enable partition type GUID for QCS9100/QCM6490/QCS615 boards

Quoted 27 lines · Balaji Selvanathan

Enable CONFIG_PARTITION_TYPE_GUID and configure SCSI environment partition type GUID for QCS9100, QCM6490 and QCS615 configurations. This allows these platforms to locate the environment partition using GPT type GUID instead of UUID.

---
Changes in v4:
- Add type guid configs to QCS9100 defconfig

Changes in v3:
- No changes

Changes in v2:
- Enable above new config in qcom_qcs615_defconfig and qcm6490_defconfig

---
 configs/qcm6490_defconfig      | 4 ++++
 configs/qcom_qcs615_defconfig  | 4 ++++
 configs/qcom_qcs9100_defconfig | 3 ++-
 3 files changed, 10 insertions(+), 1 deletion(-)
configs/qcm6490_defconfig +0 -0
index b088367f86c..9560886a37a 100644

configs/qcm6490_defconfig CONFIG_DEFAULT_DEVICE_TREE="qcom/qcs6490-rb3gen2" · line 22

Quoted 7 lines
configs/qcm6490_defconfig +4 -0
@@ -16,3 +16,7 @@ CONFIG_DEFAULT_DEVICE_TREE="qcom/qcs6490-rb3gen2"
 
 CONFIG_FASTBOOT_BUF_ADDR=0xd8800000
 CONFIG_PHY_QCOM_QMP_COMBO=y
+
+CONFIG_ENV_IS_IN_SCSI=y
+CONFIG_ENV_SCSI_PART_USE_TYPE_GUID=y
+CONFIG_ENV_SCSI_PART_TYPE_GUID="bc0330eb-3410-4951-a617-03898dbe3372"

These config options are common among targets, can you rather add an env related config fragment which can be included in all these defconfigs.

Also, please add the partition name here as a comment to easily locate the partition.

-Sumit

Quoted 29 lines
configs/qcom_qcs615_defconfig +4 -0
index 27666a8129d..d0ffa567619 100644
@@ -22,3 +22,7 @@ CONFIG_REMAKE_ELF=y
 CONFIG_TEXT_BASE=0x9fc00000
 
 CONFIG_FASTBOOT_BUF_ADDR=0xa1600000
+
+CONFIG_ENV_IS_IN_SCSI=y
+CONFIG_ENV_SCSI_PART_USE_TYPE_GUID=y
+CONFIG_ENV_SCSI_PART_TYPE_GUID="bc0330eb-3410-4951-a617-03898dbe3372"
configs/qcom_qcs9100_defconfig +2 -1
index 082106157bb..fbaf21952f2 100644
@@ -11,6 +11,7 @@ CONFIG_REMAKE_ELF=y
 CONFIG_FASTBOOT_BUF_ADDR=0xdb300000
 CONFIG_DEFAULT_DEVICE_TREE="qcom/qcs9100-ride-r3"
 CONFIG_ENV_IS_IN_SCSI=y
-CONFIG_ENV_SCSI_PART_UUID="71cb9cd0-acf1-b6cb-ad91-be9572fe11a9"
+CONFIG_ENV_SCSI_PART_USE_TYPE_GUID=y
+CONFIG_ENV_SCSI_PART_TYPE_GUID="bc0330eb-3410-4951-a617-03898dbe3372"
 # CONFIG_ENV_IS_DEFAULT is not set
 # CONFIG_ENV_IS_NOWHERE is not set
Signature · 2 lines
-- 
2.34.1
#14 lore raw

PATCH v4 8/8 test: dm: Add partition type GUID lookup test

In reply to Balaji Selvanathan

Add a unit test for the partition type GUID lookup functionality. The test verifies that partitions can be correctly identified by their type GUID, specifically testing the ChromeOS kernel partition lookup.

---
Changes in v4:
- Return -EAGAIN instead of EOPNOTSUPP
- Add extra asserts for kernel partition

Changes in v3:
- Add unit test for the partition type GUID lookup functionality

---
 test/dm/part.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)
test/dm/part.c +49 -0
index caae23bd4aa..7a427d3d41d 100644
@@ -8,9 +8,13 @@
 #include <mmc.h>
 #include <part.h>
 #include <part_efi.h>
+#include <asm/global_data.h>
+#include <dm/lists.h>
 #include <dm/test.h>
 #include <test/ut.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static int do_test(struct unit_test_state *uts, int expected,
 		   const char *part_str, bool whole)
 {
@@ -195,3 +199,48 @@ static int dm_test_part_get_info_by_type(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_part_get_info_by_type, UTF_SCAN_PDATA | UTF_SCAN_FDT);
+
+static int dm_test_part_get_info_by_type_guid(struct unit_test_state *uts)
+{
+	struct udevice *dev, *blk_dev;
+	struct blk_desc *desc;
+	struct disk_partition info;
+	ofnode root, node;
+	int partnum;
+
+	if (!IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))
+		return -EAGAIN;
+
+	/* Bind the mmc5 node (ChromeOS image with type GUIDs) */
+	root = oftree_root(oftree_default());
+	node = ofnode_find_subnode(root, "mmc5");
+	ut_assert(ofnode_valid(node));
+	ut_assertok(lists_bind_fdt(gd->dm_root, node, &dev, NULL, false));
+
+	/* Get the MMC device (probes it), then walk MMC -> BLK parent link */
+	ut_assertok(uclass_get_device_by_seq(UCLASS_MMC, 5, &dev));
+	ut_assertok(blk_get_from_parent(dev, &blk_dev));
+	desc = dev_get_uclass_plat(blk_dev);
+	ut_assert(desc);
+
+	/*
+	 * Test: look up the first ChromeOS kernel partition by type GUID.
+	 * In the ChromeOS image KERN_A is the first partition carrying the
+	 * ChromeOS kernel type GUID (fe3a2a5d-...). This is partition 2.
+	 */
+	partnum = part_get_info_by_type_guid(desc,
+					     "FE3A2A5D-4F32-41A7-B725-ACCC3285A309",
+					     &info);
+	ut_asserteq(2, partnum);
+	ut_asserteq_str("KERN_A", info.name);
+
+	/* Test: non-existent GUID must return -ENOENT */
+	ut_asserteq(-ENOENT,
+		    part_get_info_by_type_guid(desc,
+					       "00000000-0000-0000-0000-000000000000",
+					       &info));
+
+	return 0;
+}
+
+DM_TEST(dm_test_part_get_info_by_type_guid, UTF_SCAN_PDATA | UTF_SCAN_FDT);
Signature · 1 line
2.34.1