Skip to contentSkip to conversation

fdt: Fixup only valid memory banks

PATCH New Thierry Reding 3 participants 4 messages Jan 30, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fdt: Fixup only valid memory banks

From: Thierry Reding <[email protected]>

Memory banks with address 0 and size 0 are empty and should not be passed to the OS via device tree.

---
 common/fdt_support.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
common/fdt_support.c +7 -1
index 724452d75452..8b33f6773d27 100644
@@ -457,7 +457,7 @@ int fdt_record_loadable(void *blob, u32 index, const char *name,
 int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks)
 {
 	int err, nodeoffset;
-	int len;
+	int len, i;
 	u8 tmp[MEMORY_BANKS_MAX * 16]; /* Up to 64-bit address + 64-bit size */
 
 	if (banks > MEMORY_BANKS_MAX) {
@@ -489,6 +489,12 @@ int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks)
 	if (!banks)
 		return 0;
 
+	for (i = 0; i < banks; i++)
+		if (start[i] == 0 && size[i] == 0)
+			break;
+
+	banks = i;
+
 	len = fdt_pack_reg(blob, tmp, start, size, banks);
 
 	err = fdt_setprop(blob, nodeoffset, "reg", tmp, len);
Signature · 1 line
2.15.1
#1 lore raw

PATCH 1/1 fdt: Fixup only valid memory banks

Hi,

Quoted 27 lines · On Tue, 30 Jan 2018 11:34:17 +0100 Thierry Reding wrote:

From: Thierry Reding <[email protected]>

Memory banks with address 0 and size 0 are empty and should not be passed to the OS via device tree.

---
 common/fdt_support.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
common/fdt_support.c +1 -1
index 724452d75452..8b33f6773d27 100644
@@ -457,7 +457,7 @@ int fdt_record_loadable(void *blob, u32 index, const char *name,
 int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks)
 {
 	int err, nodeoffset;
-	int len;
+	int len, i;
 	u8 tmp[MEMORY_BANKS_MAX * 16]; /* Up to 64-bit address + 64-bit size */
 
 	if (banks > MEMORY_BANKS_MAX) {
@@ -489,6 +489,12 @@ int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks)
 	if (!banks)
 		return 0;

common/fdt_support.c int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks) · line 500

Quoted 10 lines
common/fdt_support.c +6 -0
 
+	for (i = 0; i < banks; i++)
+		if (start[i] == 0 && size[i] == 0)
+			break;
+
+	banks = i;
+
 	len = fdt_pack_reg(blob, tmp, start, size, banks);
 
 	err = fdt_setprop(blob, nodeoffset, "reg", tmp, len);

Does an empty bank always imply the end of the list, or Is it a valid scenario to have intervening empty banks?

Lothar Waßmann

#2 lore raw

PATCH 1/1 fdt: Fixup only valid memory banks

Quoted 38 lines · Lothar Waßmann

Hi,

Quoted 35 lines · On Tue, 30 Jan 2018 11:34:17 +0100 Thierry Reding wrote:

From: Thierry Reding <[email protected]>

Memory banks with address 0 and size 0 are empty and should not be passed to the OS via device tree.

---
 common/fdt_support.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
common/fdt_support.c +7 -1
index 724452d75452..8b33f6773d27 100644
@@ -457,7 +457,7 @@ int fdt_record_loadable(void *blob, u32 index, const char *name,
 int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks)
 {
 	int err, nodeoffset;
-	int len;
+	int len, i;
 	u8 tmp[MEMORY_BANKS_MAX * 16]; /* Up to 64-bit address + 64-bit size */
 
 	if (banks > MEMORY_BANKS_MAX) {
@@ -489,6 +489,12 @@ int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks)
 	if (!banks)
 		return 0;
 
+	for (i = 0; i < banks; i++)
+		if (start[i] == 0 && size[i] == 0)
+			break;
+
+	banks = i;
+
 	len = fdt_pack_reg(blob, tmp, start, size, banks);
 
Quoted 4 lines

common/fdt_support.c int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks) · line 500

Quoted 2 lines
common/fdt_support.c +0 -0
 	err = fdt_setprop(blob, nodeoffset, "reg", tmp, len);

Does an empty bank always imply the end of the list, or Is it a valid scenario to have intervening empty banks?

I think it's a fair assumption that there aren't going to be any holes. The vast majority of boards will only every initialize a single bank or perhaps two. There's a few odd ones (hisilicon/hikey for example) that adds more, but they are still all contiguous.

Thierry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180130/5225481b/attachment.sig>

#3 lore raw

PATCH 1/1 fdt: Fixup only valid memory banks

In reply to Thierry Reding

common/fdt_support.c int fdt_fixup_memory_banks(void *blob, u64 start[], u64 size[], int banks) · line 496

Quoted 13 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Memory banks with address 0 and size 0 are empty and should not be passed to the OS via device tree.

if (!banks)
return 0;

common/fdt_support.c +5 -0
+	for (i = 0; i < banks; i++)
+		if (start[i] == 0 && size[i] == 0)
+			break;
+
+	banks = i;

Do we want to move the for loop above the check for if (!banks)?

Should we put braces around the multi-line body of the for loop?

Aside from that,

Quoted 4 lines

+
len = fdt_pack_reg(blob, tmp, start, size, banks);

err = fdt_setprop(blob, nodeoffset, "reg", tmp, len);