Skip to contentSkip to conversation

env: mmc: Clean up macro usage

PATCH In review Marek Vasut 5 participants 13 messages Feb 9, 2023 – Feb 24, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 env: mmc: Clean up macro usage

Consistently use 'if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))' instead of mix of ifdef.

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
---
V2: Replace CONFIG_IS_ENABLED(PARTITION_TYPE_GUID) with IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)

---
 env/mmc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
env/mmc.c +1 -3
index 5b01f657a7a..d51a5579128 100644
@@ -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 (IS_ENABLED(CONFIG_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 */
Signature · 1 line
2.39.1
#1 lore raw

PATCH v2 2/2 env: mmc: Apply GPT only on eMMC user HW partition

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")

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
---
V2: Rebase on changes in 1/2

---
 env/mmc.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
env/mmc.c +8 -4
index d51a5579128..88f8a9a8978 100644
@@ -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 (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) {
+	if (IS_ENABLED(CONFIG_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);
Signature · 1 line
2.39.1
Reviewed-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] env: mmc: Apply GPT only on eMMC user HW partition

Quoted 10 lines · Marek Vasut

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")

So you're saying that today, you cannot make use of this feature and put the environment on one of the boot partitions, as it doesn't work? If so, then yes, this is the first step forward and someone else with that wants the case I described here can fix things further.

Signature · 1 line
Tom
#3 lore raw

Re: [PATCH v2 2/2] env: mmc: Apply GPT only on eMMC user HW partition

Quoted 7 lines · Tom Rini
Quoted 5 lines · Marek Vasut

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.

Quoted 8 lines
Quoted 5 lines

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")

So you're saying that today, you cannot make use of this feature and put the environment on one of the boot partitions, as it doesn't work?

Today you cannot place env into GPT which is located in eMMC BOOT HW partitions, that only works for GPT which is located in eMMC USER HW partition.

Quoted 3 lines

If
so, then yes, this is the first step forward and someone else with that wants the case I described here can fix things further.

I'm not even sure whether it makes sense to have 4 MiB or so GPT in eMMC BOOT HW partitions in the first place, but sure, if someone needs that at some later point, why not.

Quoted 1 line
#4 lore raw

Re: [PATCH v2 2/2] env: mmc: Apply GPT only on eMMC user HW partition

In reply to Marek Vasut
Quoted 11 lines · Marek Vasut

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")

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
Reviewed-by on v2 1/2
#7 lore raw
In reply to Marek Vasut
Quoted 10 lines

-----Original Message-----
From: U-Boot <[email protected]> On Behalf Of Marek Vasut
Sent: Thursday, February 9, 2023 9:30 PM
To: [email protected]
Cc: Marek Vasut <[email protected]>; Patrice Chotard <[email protected]>; Patrick Delaunay <[email protected]>; Tom Rini <[email protected]>
Subject: [PATCH v2 1/2] env: mmc: Clean up macro usage

Quoted 4 lines

Consistently use 'if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))' instead of mix of ifdef.

Best Regards,
Jaehoon Chung

Quoted 34 lines

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
---
V2: Replace CONFIG_IS_ENABLED(PARTITION_TYPE_GUID) with IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)

---
 env/mmc.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
env/mmc.c +1 -4
index 5b01f657a7a..d51a5579128 100644
@@ -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 (IS_ENABLED(CONFIG_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 */
--

2.39.1

#8 lore raw
In reply to Marek Vasut

Hi Marek,

Quoted 29 lines · Marek Vasut

Consistently use 'if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))' instead of mix of ifdef.

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
---
V2: Replace CONFIG_IS_ENABLED(PARTITION_TYPE_GUID) with IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)

---
  env/mmc.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
env/mmc.c +1 -2
index 5b01f657a7a..d51a5579128 100644
@@ -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 (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID) && !str) {
  			const efi_guid_t env_guid = PARTITION_U_BOOT_ENVIRONMENT;
  			efi_guid_t type_guid;
 

env/mmc.c static inline int mmc_offset_try_partition(const char *str, int copy, s64 *val) · line 86

Quoted 7 lines
env/mmc.c +0 -1
@@ -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 */

If I remenber, I try this test with IS_ENABLED when I propose my patch

and I have compilation issue on next line

+            uuid_str_to_bin(info.type_guid, type_guid.b, UUID_STR_FORMAT_GUID);

because "info.type_guid" don't exist in struct disk_partition

see ./include/part.h:59

struct disk_partition {
    lbaint_t    start;    /* # of first block in partition    */
...
#ifdef CONFIG_PARTITION_TYPE_GUID
    char    type_guid[UUID_STR_LEN + 1];    /* type GUID as string, if exists    */ #endif
...
};

Regards

Patrick

#9 lore raw
Quoted 1 line · Patrick DELAUNAY

Hi Marek,

Hi,

Quoted 52 lines · Marek Vasut
Quoted 28 lines

Consistently use 'if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))' instead of mix of ifdef.

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
---
V2: Replace CONFIG_IS_ENABLED(PARTITION_TYPE_GUID) with IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)
---
  env/mmc.c | 4 +---

  1 file changed, 1 insertion(+), 3 deletions(-)
env/mmc.c +1 -2
index 5b01f657a7a..d51a5579128 100644
@@ -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 (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID) && !str) {
               const efi_guid_t env_guid = PARTITION_U_BOOT_ENVIRONMENT;
               efi_guid_t type_guid;

env/mmc.c static inline int mmc_offset_try_partition(const · line 86

Quoted 7 lines
env/mmc.c +0 -1
@@ -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 */

If I remenber, I try this test with IS_ENABLED when I propose my patch

and I have compilation issue on next line

+            uuid_str_to_bin(info.type_guid, type_guid.b, UUID_STR_FORMAT_GUID);

because "info.type_guid" don't exist in struct disk_partition

see ./include/part.h:59

Quoted 9 lines

struct disk_partition {
    lbaint_t    start;    /* # of first block in partition    */
...
#ifdef CONFIG_PARTITION_TYPE_GUID
    char    type_guid[UUID_STR_LEN + 1];    /* type GUID as string, if
exists    */
#endif
...
};

Uh, which defconfig triggers this ?

Also, is there a way to deal with this failure without reinstating the ifdef ? Tom ?

#10 lore raw
Quoted 69 lines · Marek Vasut
Quoted 1 line · Patrick DELAUNAY

Hi Marek,

Hi,

Quoted 54 lines · Marek Vasut
Quoted 30 lines

Consistently use 'if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))' instead of mix of ifdef.

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
---
V2: Replace CONFIG_IS_ENABLED(PARTITION_TYPE_GUID) with IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)
---
  env/mmc.c | 4 +---

  1 file changed, 1 insertion(+), 3 deletions(-)
env/mmc.c +1 -2
index 5b01f657a7a..d51a5579128 100644
@@ -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 (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID) && !str) {
               const efi_guid_t env_guid = PARTITION_U_BOOT_ENVIRONMENT;
               efi_guid_t type_guid;

env/mmc.c static inline int mmc_offset_try_partition(const · line 86

Quoted 7 lines
env/mmc.c +0 -1
@@ -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 */

If I remenber, I try this test with IS_ENABLED when I propose my patch

and I have compilation issue on next line

+            uuid_str_to_bin(info.type_guid, type_guid.b, UUID_STR_FORMAT_GUID);

because "info.type_guid" don't exist in struct disk_partition

see ./include/part.h:59

Quoted 9 lines

struct disk_partition {
    lbaint_t    start;    /* # of first block in partition    */
...
#ifdef CONFIG_PARTITION_TYPE_GUID
    char    type_guid[UUID_STR_LEN + 1];    /* type GUID as string, if
exists    */
#endif
...
};

Quoted 4 lines

Uh, which defconfig triggers this ?

Also, is there a way to deal with this failure without reinstating the ifdef ? Tom ?

It's likely on one of the platforms that disables EFI_LOADER, where this ends up being a fail to build. I don't recall which, but I've seen it before. So we probably don't end up converting this to a macro check.

Signature · 1 line
Tom
#11 lore raw
Quoted 70 lines · Tom Rini
Quoted 69 lines · Marek Vasut
Quoted 1 line · Patrick DELAUNAY

Hi Marek,

Hi,

Quoted 63 lines · Marek Vasut
Quoted 30 lines

Consistently use 'if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))' instead of mix of ifdef.

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
---
V2: Replace CONFIG_IS_ENABLED(PARTITION_TYPE_GUID) with IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)

---
   env/mmc.c | 4 +---
   1 file changed, 1 insertion(+), 3 deletions(-)
env/mmc.c +1 -2
index 5b01f657a7a..d51a5579128 100644
@@ -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 (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID) && !str) {
               const efi_guid_t env_guid = PARTITION_U_BOOT_ENVIRONMENT;
               efi_guid_t type_guid;

env/mmc.c static inline int mmc_offset_try_partition(const · line 86

Quoted 7 lines
env/mmc.c +0 -1
@@ -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 */

If I remenber, I try this test with IS_ENABLED when I propose my patch

and I have compilation issue on next line

+            uuid_str_to_bin(info.type_guid, type_guid.b, UUID_STR_FORMAT_GUID);

because "info.type_guid" don't exist in struct disk_partition

see ./include/part.h:59

struct disk_partition {
    lbaint_t    start;    /* # of first block in partition    */
...
#ifdef CONFIG_PARTITION_TYPE_GUID
    char    type_guid[UUID_STR_LEN + 1];    /* type GUID as string, if
exists    */
#endif
...
};

Quoted 8 lines
Quoted 4 lines

Uh, which defconfig triggers this ?

Also, is there a way to deal with this failure without reinstating the ifdef ? Tom ?

It's likely on one of the platforms that disables EFI_LOADER, where this ends up being a fail to build. I don't recall which, but I've seen it before. So we probably don't end up converting this to a macro check.

Can you pick the 2/2 for starters ? It is a bugfix and applies cleanly, so let's not block that one. I'll keep 1/2 in my queue and revisit it, I see the failure in CI now.

#12 lore raw
In reply to Marek Vasut

Hi,

Quoted 70 lines · Marek Vasut
Quoted 1 line · Patrick DELAUNAY

Hi Marek,

Hi,

Quoted 54 lines · Marek Vasut
Quoted 30 lines

Consistently use 'if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID))' instead of mix of ifdef.

---
Cc: Patrice Chotard <[email protected]>
Cc: Patrick Delaunay <[email protected]>
Cc: Tom Rini <[email protected]>
---
V2: Replace CONFIG_IS_ENABLED(PARTITION_TYPE_GUID) with IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)

---
  env/mmc.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
env/mmc.c +1 -2
index 5b01f657a7a..d51a5579128 100644
@@ -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 (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID) && !str) {
              const efi_guid_t env_guid = PARTITION_U_BOOT_ENVIRONMENT;
              efi_guid_t type_guid;

env/mmc.c static inline int mmc_offset_try_partition(const · line 86

Quoted 7 lines
env/mmc.c +0 -1
@@ -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 */

If I remenber, I try this test with IS_ENABLED when I propose my patch

and I have compilation issue on next line

+ uuid_str_to_bin(info.type_guid, type_guid.b,
UUID_STR_FORMAT_GUID);

because "info.type_guid" don't exist in struct disk_partition

see ./include/part.h:59

Quoted 9 lines

struct disk_partition {
lbaint_t start; /* # of first block in partition */
...
#ifdef CONFIG_PARTITION_TYPE_GUID
char type_guid[UUID_STR_LEN + 1]; /* type GUID as string, if
exists */
#endif
...
};

Quoted 4 lines

Uh, which defconfig triggers this ?

Also, is there a way to deal with this failure without reinstating the ifdef ? Tom ?

We can create static inline accessors as we have done with some things in global_data.h

Regards,
Simon