Skip to contentSkip to conversation

rockchip: misc: Only assign serial# variable if unset

PATCH New Paul Kocialkowski 2 participants 5 messages Dec 3, 2019 – Dec 4, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 rockchip: misc: Only assign serial# variable if unset

The serial# environment variable is a read-only special variable, that can only be set once. As a result, if the environment was saved to a persistent storage location, attempting to set it again in rockchip_cpuid_set will fail and halt the boot with the following error:

Solve this by checking whether the variable is already set before.

---
 arch/arm/mach-rockchip/misc.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
arch/arm/mach-rockchip/misc.c +9 -5
index bed4317f7ece..a0c6a1c0b266 100644
@@ -108,12 +108,16 @@ int rockchip_cpuid_set(const u8 *cpuid, const u32 cpuid_length)
 		high[i] = cpuid[i << 1];
 	}
 
-	serialno = crc32_no_comp(0, low, 8);
-	serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32;
-	snprintf(serialno_str, sizeof(serialno_str), "%016llx", serialno);
-
 	env_set("cpuid#", cpuid_str);
-	env_set("serial#", serialno_str);
+
+	if (!env_get("serial#")) {
+		serialno = crc32_no_comp(0, low, 8);
+		serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32;
+		snprintf(serialno_str, sizeof(serialno_str), "%016llx",
+			 serialno);
+
+		env_set("serial#", serialno_str);
+	}
 
 	return 0;
 }
Signature · 1 line
2.24.0
#1 lore raw

PATCH 2/2 rockchip: misc: Don't fail if ethaddr is already set

rockchip_setup_macaddr will return -1 if ethaddr is already set, which gets propagated to misc_init_r and eventually halts the boot process.

While checking that the variable is not already set before attempting to setit is legitimate (it's a set-once variable), this is no good reason to halt the boot process.

Return the success return code if the variable is already set instead.

---
 arch/arm/mach-rockchip/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-rockchip/misc.c +1 -1
index a0c6a1c0b266..bce10bb04f8f 100644
@@ -29,7 +29,7 @@ int rockchip_setup_macaddr(void)
 
 	/* Only generate a MAC address, if none is set in the environment */
 	if (env_get("ethaddr"))
-		return -1;
+		return 0;
 
 	if (!cpuid) {
 		debug("%s: could not retrieve 'cpuid#'\n", __func__);
Signature · 1 line
2.24.0
#2 lore raw

PATCH 2/2 rockchip: misc: Don't fail if ethaddr is already set

Quoted 10 lines · Paul Kocialkowski

rockchip_setup_macaddr will return -1 if ethaddr is already set, which gets propagated to misc_init_r and eventually halts the boot process.

While checking that the variable is not already set before attempting to setit is legitimate (it's a set-once variable), this is no good reason to halt the boot process.

Return the success return code if the variable is already set instead.

Same as "rockchip: misc: don't fail if eth_addr already set" from november 29 ;-)

Quoted 17 lines
---
  arch/arm/mach-rockchip/misc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/mach-rockchip/misc.c +1 -1
index a0c6a1c0b266..bce10bb04f8f 100644
@@ -29,7 +29,7 @@ int rockchip_setup_macaddr(void)
 
  	/* Only generate a MAC address, if none is set in the environment */
  	if (env_get("ethaddr"))
-		return -1;
+		return 0;
 
  	if (!cpuid) {
  		debug("%s: could not retrieve 'cpuid#'\n", __func__);
#3 lore raw

PATCH 1/2 rockchip: misc: Only assign serial# variable if unset

In reply to Paul Kocialkowski

Hi Paul,

Quoted 8 lines · Paul Kocialkowski

The serial# environment variable is a read-only special variable, that can only be set once. As a result, if the environment was saved to a persistent storage location, attempting to set it again in rockchip_cpuid_set will fail and halt the boot with the following error:

Solve this by checking whether the variable is already set before.

it looks like we're fixing the same problems a lot. Yesterday I also got a patch from Miquel about the px30 iommu clocks ;-) .

Here it's the same as "rockchip: misc: protect serial# from getting overwritten"
from november 29 ;-)

Heiko

Quoted 30 lines
---
  arch/arm/mach-rockchip/misc.c | 14 +++++++++-----
  1 file changed, 9 insertions(+), 5 deletions(-)
arch/arm/mach-rockchip/misc.c +9 -5
index bed4317f7ece..a0c6a1c0b266 100644
@@ -108,12 +108,16 @@ int rockchip_cpuid_set(const u8 *cpuid, const u32 cpuid_length)
  		high[i] = cpuid[i << 1];
  	}
 
-	serialno = crc32_no_comp(0, low, 8);
-	serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32;
-	snprintf(serialno_str, sizeof(serialno_str), "%016llx", serialno);
-
  	env_set("cpuid#", cpuid_str);
-	env_set("serial#", serialno_str);
+
+	if (!env_get("serial#")) {
+		serialno = crc32_no_comp(0, low, 8);
+		serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32;
+		snprintf(serialno_str, sizeof(serialno_str), "%016llx",
+			 serialno);
+
+		env_set("serial#", serialno_str);
+	}
 
  	return 0;
  }
#4 lore raw

PATCH 1/2 rockchip: misc: Only assign serial# variable if unset

Hi Heiko,

Quoted 10 lines · Heiko Stuebner

Hi Paul,

Quoted 7 lines · Paul Kocialkowski

The serial# environment variable is a read-only special variable, that can only be set once. As a result, if the environment was saved to a persistent storage location, attempting to set it again in rockchip_cpuid_set will fail and halt the boot with the following error:

Solve this by checking whether the variable is already set before.

Quoted 8 lines
Quoted 1 line

it looks like we're fixing the same problems a lot. Yesterday I also got a patch from Miquel about the px30 iommu clocks ;-) .

Here it's the same as "rockchip: misc: protect serial# from getting overwritten"
from november 29 ;-)

Hehe good catch! We'll try to keep better track of the list before sending fixes next time ;)

Cheers,

Paul

Quoted 32 lines

Heiko

Quoted 28 lines
---
  arch/arm/mach-rockchip/misc.c | 14 +++++++++-----
  1 file changed, 9 insertions(+), 5 deletions(-)
arch/arm/mach-rockchip/misc.c +9 -5
index bed4317f7ece..a0c6a1c0b266 100644
@@ -108,12 +108,16 @@ int rockchip_cpuid_set(const u8 *cpuid, const u32 cpuid_length)
  		high[i] = cpuid[i << 1];
  	}
-	serialno = crc32_no_comp(0, low, 8);
-	serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32;
-	snprintf(serialno_str, sizeof(serialno_str), "%016llx", serialno);
-
  	env_set("cpuid#", cpuid_str);
-	env_set("serial#", serialno_str);
+
+	if (!env_get("serial#")) {
+		serialno = crc32_no_comp(0, low, 8);
+		serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32;
+		snprintf(serialno_str, sizeof(serialno_str), "%016llx",
+			 serialno);
+
+		env_set("serial#", serialno_str);
+	}
  	return 0;
  }
Signature · 10 lines
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20191204/fa334960/attachment.sig>