All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] env: mmc: Clean up macro usage
@ 2023-02-08 11:32 Marek Vasut
  2023-02-08 11:32 ` [PATCH 2/2] env: mmc: Apply GPT only on eMMC user HW partition Marek Vasut
  2023-02-08 15:22 ` [PATCH 1/2] env: mmc: Clean up macro usage Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Marek Vasut @ 2023-02-08 11:32 UTC (permalink / raw)
  To: u-boot; +Cc: Marek Vasut, Patrice Chotard, Patrick Delaunay, Tom Rini

Consistently use 'if (CONFIG_IS_ENABLED(PARTITION_TYPE_GUID))' instead of
mix of ifdef and IS_ENABLED. This deals with xPL variants of the config
option and trims ifdeffery.

Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: Patrice Chotard <patrice.chotard@foss.st.com>
Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
Cc: Tom Rini <trini@konsulko.com>
---
 env/mmc.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/env/mmc.c b/env/mmc.c
index 5b01f657a7a..b34a8dd982e 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -73,8 +73,7 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
 
 		if (str && !strncmp((const char *)info.name, str, sizeof(info.name)))
 			break;
-#ifdef CONFIG_PARTITION_TYPE_GUID
-		if (!str) {
+		if (CONFIG_IS_ENABLED(PARTITION_TYPE_GUID) && !str) {
 			const efi_guid_t env_guid = PARTITION_U_BOOT_ENVIRONMENT;
 			efi_guid_t type_guid;
 
@@ -82,7 +81,6 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
 			if (!memcmp(&env_guid, &type_guid, sizeof(efi_guid_t)))
 				break;
 		}
-#endif
 	}
 
 	/* round up to info.blksz */
@@ -121,7 +119,7 @@ static inline s64 mmc_offset(int copy)
 	}
 
 	/* try the GPT partition with "U-Boot ENV" TYPE GUID */
-	if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) {
+	if (CONFIG_IS_ENABLED(PARTITION_TYPE_GUID)) {
 		err = mmc_offset_try_partition(NULL, copy, &val);
 		if (!err)
 			return val;
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] env: mmc: Apply GPT only on eMMC user HW partition
  2023-02-08 11:32 [PATCH 1/2] env: mmc: Clean up macro usage Marek Vasut
@ 2023-02-08 11:32 ` Marek Vasut
  2023-02-08 15:22 ` [PATCH 1/2] env: mmc: Clean up macro usage Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Marek Vasut @ 2023-02-08 11:32 UTC (permalink / raw)
  To: u-boot; +Cc: Marek Vasut, Patrice Chotard, Patrick Delaunay, Tom Rini

Apply the GPT U-Boot environment GUID type look up only on eMMC user
HW partition, do not apply the look up on eMMC boot HW partitions as
mmc_offset_try_partition() assumes either SD partitions or eMMC user
HW partition.

This fixes environment operation on systems where CONFIG_SYS_MMC_ENV_PART
is non-zero and CONFIG_SYS_REDUNDAND_ENVIRONMENT is set.

Fixes: 80105d8fd52 ("env: mmc: select GPT env partition by type guid")
Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: Patrice Chotard <patrice.chotard@foss.st.com>
Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
Cc: Tom Rini <trini@konsulko.com>
---
 env/mmc.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/env/mmc.c b/env/mmc.c
index b34a8dd982e..25df750ffd9 100644
--- a/env/mmc.c
+++ b/env/mmc.c
@@ -92,7 +92,7 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
 	return 0;
 }
 
-static inline s64 mmc_offset(int copy)
+static inline s64 mmc_offset(struct mmc *mmc, int copy)
 {
 	const struct {
 		const char *offset_redund;
@@ -106,8 +106,12 @@ static inline s64 mmc_offset(int copy)
 	s64 val = 0, defvalue;
 	const char *propname;
 	const char *str;
+	int hwpart = 0;
 	int err;
 
+	if (IS_ENABLED(CONFIG_SYS_MMC_ENV_PART))
+		hwpart = mmc_get_env_part(mmc);
+
 	/* look for the partition in mmc CONFIG_SYS_MMC_ENV_DEV */
 	str = ofnode_conf_read_str(dt_prop.partition);
 	if (str) {
@@ -119,7 +123,7 @@ static inline s64 mmc_offset(int copy)
 	}
 
 	/* try the GPT partition with "U-Boot ENV" TYPE GUID */
-	if (CONFIG_IS_ENABLED(PARTITION_TYPE_GUID)) {
+	if (CONFIG_IS_ENABLED(PARTITION_TYPE_GUID) && hwpart == 0) {
 		err = mmc_offset_try_partition(NULL, copy, &val);
 		if (!err)
 			return val;
@@ -136,7 +140,7 @@ static inline s64 mmc_offset(int copy)
 	return ofnode_conf_read_int(propname, defvalue);
 }
 #else
-static inline s64 mmc_offset(int copy)
+static inline s64 mmc_offset(struct mmc *mmc, int copy)
 {
 	s64 offset = ENV_MMC_OFFSET;
 
@@ -149,7 +153,7 @@ static inline s64 mmc_offset(int copy)
 
 __weak int mmc_get_env_addr(struct mmc *mmc, int copy, u32 *env_addr)
 {
-	s64 offset = mmc_offset(copy);
+	s64 offset = mmc_offset(mmc, copy);
 
 	if (offset == ENV_MMC_INVALID_OFFSET) {
 		printf("Invalid ENV offset in MMC, copy=%d\n", copy);
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] env: mmc: Clean up macro usage
  2023-02-08 11:32 [PATCH 1/2] env: mmc: Clean up macro usage Marek Vasut
  2023-02-08 11:32 ` [PATCH 2/2] env: mmc: Apply GPT only on eMMC user HW partition Marek Vasut
@ 2023-02-08 15:22 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2023-02-08 15:22 UTC (permalink / raw)
  To: Marek Vasut; +Cc: u-boot, Patrice Chotard, Patrick Delaunay

[-- Attachment #1: Type: text/plain, Size: 1869 bytes --]

On Wed, Feb 08, 2023 at 12:32:43PM +0100, Marek Vasut wrote:
> Consistently use 'if (CONFIG_IS_ENABLED(PARTITION_TYPE_GUID))' instead of
> mix of ifdef and IS_ENABLED. This deals with xPL variants of the config
> option and trims ifdeffery.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> ---
> Cc: Patrice Chotard <patrice.chotard@foss.st.com>
> Cc: Patrick Delaunay <patrick.delaunay@foss.st.com>
> Cc: Tom Rini <trini@konsulko.com>
> ---
>  env/mmc.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/env/mmc.c b/env/mmc.c
> index 5b01f657a7a..b34a8dd982e 100644
> --- a/env/mmc.c
> +++ b/env/mmc.c
> @@ -73,8 +73,7 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
>  
>  		if (str && !strncmp((const char *)info.name, str, sizeof(info.name)))
>  			break;
> -#ifdef CONFIG_PARTITION_TYPE_GUID
> -		if (!str) {
> +		if (CONFIG_IS_ENABLED(PARTITION_TYPE_GUID) && !str) {
>  			const efi_guid_t env_guid = PARTITION_U_BOOT_ENVIRONMENT;
>  			efi_guid_t type_guid;
>  
> @@ -82,7 +81,6 @@ static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val)
>  			if (!memcmp(&env_guid, &type_guid, sizeof(efi_guid_t)))
>  				break;
>  		}
> -#endif
>  	}
>  
>  	/* round up to info.blksz */
> @@ -121,7 +119,7 @@ static inline s64 mmc_offset(int copy)
>  	}
>  
>  	/* try the GPT partition with "U-Boot ENV" TYPE GUID */
> -	if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) {
> +	if (CONFIG_IS_ENABLED(PARTITION_TYPE_GUID)) {
>  		err = mmc_offset_try_partition(NULL, copy, &val);
>  		if (!err)
>  			return val;

I don't think this is right as we don't have xPL options for
PARTITION_TYPE_GUID and do want to have the same environment location
used in all stages (aside from when xPL says it only has no where for
the env), yes?

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-02-08 15:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-08 11:32 [PATCH 1/2] env: mmc: Clean up macro usage Marek Vasut
2023-02-08 11:32 ` [PATCH 2/2] env: mmc: Apply GPT only on eMMC user HW partition Marek Vasut
2023-02-08 15:22 ` [PATCH 1/2] env: mmc: Clean up macro usage Tom Rini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.