Skip to contentSkip to conversation

hwconfig: Fix dummy initialization of {board, cpu}_hwconfig

PATCH Superseded Kumar Gala 3 participants 4 messages Nov 30, 2010

lore
Share & tools
lore

Kumar Gala

author
#0 lore raw

PATCH v3 1/1 hwconfig: Fix dummy initialization of {board, cpu}_hwconfig

Since board_hwconfig & cpu_hwconfig are defined as weak and dont have a default value they will get put into the BSS if they aren't defined elsewhere. This is problematic as we try to utilize hwconfig before we've relocated and thus BSS isn't setup.

Instead of giving dummy values in the board files that utilize this feature, we can just initialize the variables to an empty string and thus move them out of the BSS if they aren't defined elsewhere.

Also made board_hwconfig & cpu_hwconfig arrays to reduce size associated with string pointers vs arrays.

---
* Removed null checks for board_hwconfig & cpu_hwconfig

 board/freescale/mpc8641hpcn/mpc8641hpcn.c |    3 ---
 board/freescale/p2020ds/p2020ds.c         |    3 ---
 common/hwconfig.c                         |   14 ++++++--------
 3 files changed, 6 insertions(+), 14 deletions(-)
board/freescale/mpc8641hpcn/mpc8641hpcn.c +0 -3
index 812111d..882ff0b 100644
@@ -60,9 +60,6 @@ int checkboard(void)
 	return 0;
 }
 
-const char *board_hwconfig = "foo:bar=baz";
-const char *cpu_hwconfig = "foo:bar=baz";
-
 phys_size_t
 initdram(int board_type)
 {
board/freescale/p2020ds/p2020ds.c +0 -3
index b507677..b05ef98 100644
@@ -69,9 +69,6 @@ int checkboard(void)
 	return 0;
 }
 
-const char *board_hwconfig = "foo:bar=baz";
-const char *cpu_hwconfig = "foo:bar=baz";
-
 phys_size_t initdram(int board_type)
 {
 	phys_size_t dram_size = 0;
common/hwconfig.c +6 -8
index 3c9759f..da8d3ed 100644
@@ -68,8 +68,8 @@ next:
 	return NULL;
 }
 
-const char *cpu_hwconfig __attribute__((weak));
-const char *board_hwconfig __attribute__((weak));
+const char cpu_hwconfig[] __attribute__((weak)) = "";
+const char board_hwconfig[] __attribute__((weak)) = "";
 
 #define HWCONFIG_PRE_RELOC_BUF_SIZE	128
 
@@ -96,13 +96,11 @@ static const char *__hwconfig(const char *opt, size_t *arglen)
 		return hwconfig_parse(env_hwconfig, strlen(env_hwconfig),
 				      opt, ";", ':', arglen);
 
-	if (board_hwconfig)
-		return hwconfig_parse(board_hwconfig, strlen(board_hwconfig),
-				      opt, ";", ':', arglen);
+	return hwconfig_parse(board_hwconfig, strlen(board_hwconfig),
+			opt, ";", ':', arglen);
 
-	if (cpu_hwconfig)
-		return hwconfig_parse(cpu_hwconfig, strlen(cpu_hwconfig),
-				      opt, ";", ':', arglen);
+	return hwconfig_parse(cpu_hwconfig, strlen(cpu_hwconfig),
+			opt, ";", ':', arglen);
 
 	return NULL;
 }
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH v3 1/1 hwconfig: Fix dummy initialization of {board, cpu}_hwconfig

Dear Kumar Gala,

Quoted 12 lines · In message <[email protected]> you…

Since board_hwconfig & cpu_hwconfig are defined as weak and dont have a default value they will get put into the BSS if they aren't defined elsewhere. This is problematic as we try to utilize hwconfig before we've relocated and thus BSS isn't setup.

Instead of giving dummy values in the board files that utilize this feature, we can just initialize the variables to an empty string and thus move them out of the BSS if they aren't defined elsewhere.

Also made board_hwconfig & cpu_hwconfig arrays to reduce size associated with string pointers vs arrays.

Quoted 8 lines

---
* Removed null checks for board_hwconfig & cpu_hwconfig

 board/freescale/mpc8641hpcn/mpc8641hpcn.c |    3 ---
 board/freescale/p2020ds/p2020ds.c         |    3 ---
 common/hwconfig.c                         |   14 ++++++--------
 3 files changed, 6 insertions(+), 14 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 8 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
You speak of courage. Obviously you do not know the  difference  bet-
ween  courage and foolhardiness. Always it is the brave ones who die,
the soldiers.
	-- Kor, the Klingon Commander, "Errand of Mercy",
	   stardate 3201.7
#2 lore raw

PATCH v3 1/1 hwconfig: Fix dummy initialization of {board, cpu}_hwconfig

In reply to Kumar Gala
Quoted 23 lines · On Tue, 30 Nov 2010 15:01:28 -0600 Kumar Gala <[email protected]> wrote:
common/hwconfig.c +3 -5
index 3c9759f..da8d3ed 100644
@@ -68,8 +68,8 @@ next:
 	return NULL;
 }
 
-const char *cpu_hwconfig __attribute__((weak));
-const char *board_hwconfig __attribute__((weak));
+const char cpu_hwconfig[] __attribute__((weak)) = "";
+const char board_hwconfig[] __attribute__((weak)) = "";
 
 #define HWCONFIG_PRE_RELOC_BUF_SIZE	128
 
@@ -96,13 +96,11 @@ static const char *__hwconfig(const char *opt, size_t *arglen)
 		return hwconfig_parse(env_hwconfig, strlen(env_hwconfig),
 				      opt, ";", ':', arglen);
 
-	if (board_hwconfig)
-		return hwconfig_parse(board_hwconfig, strlen(board_hwconfig),
-				      opt, ";", ':', arglen);
+	return hwconfig_parse(board_hwconfig, strlen(board_hwconfig),

common/hwconfig.c static const char *__hwconfig(const char *opt, size_t *arglen) · line 106

Quoted 10 lines
common/hwconfig.c +3 -3
+			opt, ";", ':', arglen);
 
-	if (cpu_hwconfig)
-		return hwconfig_parse(cpu_hwconfig, strlen(cpu_hwconfig),
-				      opt, ";", ':', arglen);
+	return hwconfig_parse(cpu_hwconfig, strlen(cpu_hwconfig),
+			opt, ";", ':', arglen);
 
 	return NULL;
 }

Hmm. "return x; return y; return NULL;"

Was the presence of a board hwconfig really intended to override, rather than add to, the cpu hwconfig? Should we check the return of the first hwconfig_parse to see if it found anything?

-Scott

author
#3 lore raw

PATCH v3 1/1 hwconfig: Fix dummy initialization of {board, cpu}_hwconfig

Quoted 34 lines · Scott Wood
Quoted 31 lines · On Tue, 30 Nov 2010 15:01:28 -0600 Kumar Gala <[email protected]> wrote:
common/hwconfig.c +6 -8
index 3c9759f..da8d3ed 100644
@@ -68,8 +68,8 @@ next:
 	return NULL;
 }
 
-const char *cpu_hwconfig __attribute__((weak));
-const char *board_hwconfig __attribute__((weak));
+const char cpu_hwconfig[] __attribute__((weak)) = "";
+const char board_hwconfig[] __attribute__((weak)) = "";
 
 #define HWCONFIG_PRE_RELOC_BUF_SIZE	128
 
@@ -96,13 +96,11 @@ static const char *__hwconfig(const char *opt, size_t *arglen)
 		return hwconfig_parse(env_hwconfig, strlen(env_hwconfig),
 				      opt, ";", ':', arglen);
 
-	if (board_hwconfig)
-		return hwconfig_parse(board_hwconfig, strlen(board_hwconfig),
-				      opt, ";", ':', arglen);
+	return hwconfig_parse(board_hwconfig, strlen(board_hwconfig),
+			opt, ";", ':', arglen);
 
-	if (cpu_hwconfig)
-		return hwconfig_parse(cpu_hwconfig, strlen(cpu_hwconfig),
-				      opt, ";", ':', arglen);
+	return hwconfig_parse(cpu_hwconfig, strlen(cpu_hwconfig),
+			opt, ";", ':', arglen);
 
Quoted 8 lines

common/hwconfig.c static const char *__hwconfig(const char *opt, size_t *arglen) · line 106

Quoted 2 lines
common/hwconfig.c +0 -0
 	return NULL;
 }

Hmm. "return x; return y; return NULL;"

Was the presence of a board hwconfig really intended to override, rather than add to, the cpu hwconfig? Should we check the return of the first hwconfig_parse to see if it found anything?

Yeah, I'll fix this - didn't even notice it before.

I'm going to make it:

	ret = hwconfig_parse(env_hwconfig, ...)
	if (ret)
		return ret;
	ret = hwconfig_parse(board_hwconfig, ...)
	if (ret)
		return ret;

	return hwconfig_parse(cpu_hwconfig, ...);

- k