diff mbox series

[6/8] env: mmc: select GPT env partition by type guid

Message ID 20221110114828.6.I6580e1953c9b27a410bc6e6223aa71b118b11672@changeid
State Accepted
Commit 80105d8fd525406a8792db2cb4f1b2002349cfb7
Delegated to: Tom Rini
Headers show
Series env: mmc: improvements and corrections | expand

Commit Message

Patrick DELAUNAY Nov. 10, 2022, 10:49 a.m. UTC
Since commit c0364ce1c695 ("doc/README.gpt: define partition type GUID for
U-Boot environment"), a specific type GUID can be used to indicate
the U-Boot environment partition on the device with GPT partition table.

This patch uses this type GUID to found the env partition as fallback
when the partition name property "u-boot,mmc-env-partition" is not present
in config node or if the indicated partition name is not found.

The mmc_offset_try_partition() function is reused, it selects the first
partition with the correct type GUID when the parameter 'str' is NULL.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---

 env/mmc.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Comments

Patrice CHOTARD Dec. 6, 2022, 8:11 a.m. UTC | #1
On 11/10/22 11:49, Patrick Delaunay wrote:
> Since commit c0364ce1c695 ("doc/README.gpt: define partition type GUID for
> U-Boot environment"), a specific type GUID can be used to indicate
> the U-Boot environment partition on the device with GPT partition table.
> 
> This patch uses this type GUID to found the env partition as fallback
> when the partition name property "u-boot,mmc-env-partition" is not present
> in config node or if the indicated partition name is not found.
> 
> The mmc_offset_try_partition() function is reused, it selects the first
> partition with the correct type GUID when the parameter 'str' is NULL.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
> 
>  env/mmc.c | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/env/mmc.c b/env/mmc.c
> index 1894b6483220..bd7d51e6b633 100644
> --- a/env/mmc.c
> +++ b/env/mmc.c
> @@ -74,8 +74,18 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
>  		if (ret < 0)
>  			return ret;
>  
> -		if (!strncmp((const char *)info.name, str, sizeof(info.name)))
> +		if (str && !strncmp((const char *)info.name, str, sizeof(info.name)))
>  			break;
> +#ifdef CONFIG_PARTITION_TYPE_GUID
> +		if (!str) {
> +			const efi_guid_t env_guid = PARTITION_U_BOOT_ENVIRONMENT;
> +			efi_guid_t type_guid;
> +
> +			uuid_str_to_bin(info.type_guid, type_guid.b, UUID_STR_FORMAT_GUID);
> +			if (!memcmp(&env_guid, &type_guid, sizeof(efi_guid_t)))
> +				break;
> +		}
> +#endif
>  	}
>  
>  	/* round up to info.blksz */
> @@ -112,6 +122,13 @@ static inline s64 mmc_offset(int copy)
>  			return val;
>  	}
>  
> +	/* try the GPT partition with "U-Boot ENV" TYPE GUID */
> +	if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) {
> +		err = mmc_offset_try_partition(NULL, copy, &val);
> +		if (!err)
> +			return val;
> +	}
> +
>  	defvalue = ENV_MMC_OFFSET;
>  	propname = dt_prop.offset;
>  

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice
diff mbox series

Patch

diff --git a/env/mmc.c b/env/mmc.c
index 1894b6483220..bd7d51e6b633 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -74,8 +74,18 @@  static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
 		if (ret < 0)
 			return ret;
 
-		if (!strncmp((const char *)info.name, str, sizeof(info.name)))
+		if (str && !strncmp((const char *)info.name, str, sizeof(info.name)))
 			break;
+#ifdef CONFIG_PARTITION_TYPE_GUID
+		if (!str) {
+			const efi_guid_t env_guid = PARTITION_U_BOOT_ENVIRONMENT;
+			efi_guid_t type_guid;
+
+			uuid_str_to_bin(info.type_guid, type_guid.b, UUID_STR_FORMAT_GUID);
+			if (!memcmp(&env_guid, &type_guid, sizeof(efi_guid_t)))
+				break;
+		}
+#endif
 	}
 
 	/* round up to info.blksz */
@@ -112,6 +122,13 @@  static inline s64 mmc_offset(int copy)
 			return val;
 	}
 
+	/* try the GPT partition with "U-Boot ENV" TYPE GUID */
+	if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) {
+		err = mmc_offset_try_partition(NULL, copy, &val);
+		if (!err)
+			return val;
+	}
+
 	defvalue = ENV_MMC_OFFSET;
 	propname = dt_prop.offset;