Skip to contentSkip to conversation

board: sifive: Fix a potential build warning in board_fdt_blob_setup()

PATCH In review Bin Meng 4 participants 7 messages Sep 11, 2021 – Oct 11, 2021 1 message not in the archive SiFive drivers

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH v2 1/1 board: sifive: Fix a potential build warning in board_fdt_blob_setup()

Commit 47d73ba4f4a4 ("board: sifive: overwrite board_fdt_blob_setup in u-boot proper") added a board-specific implementation of board_fdt_blob_setup() which takes a pointer as the return value, but it does not return anything
if CONFIG_OF_SEPARATE is not enabled. This will cause a build warning seen when testing booting S-mode U-Boot directly from QEMU, per the instructions in [1]:

board/sifive/unleashed/unleashed.c: In function ‘board_fdt_blob_setup’:
board/sifive/unleashed/unleashed.c:125:1: warning: control reaches end of non-void function [-Wreturn-type]

Return &_end as the default case.

[1] https://qemu.readthedocs.io/en/latest/system/riscv/sifive_u.html#running-u-boot

---

Changes in v2:
- Correct the commit title

 board/sifive/unleashed/unleashed.c | 4 ++--
 board/sifive/unmatched/unmatched.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
board/sifive/unleashed/unleashed.c +2 -2
index 8cd514df30..33baeda986 100644
@@ -119,9 +119,9 @@ void *board_fdt_blob_setup(void)
 	if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
 		if (gd->arch.firmware_fdt_addr)
 			return (ulong *)gd->arch.firmware_fdt_addr;
-		else
-			return (ulong *)&_end;
 	}
+
+	return (ulong *)&_end;
 }
 
 int board_init(void)
board/sifive/unmatched/unmatched.c +2 -2
index d90b252bae..8773b660fa 100644
@@ -16,9 +16,9 @@ void *board_fdt_blob_setup(void)
 	if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
 		if (gd->arch.firmware_fdt_addr)
 			return (ulong *)gd->arch.firmware_fdt_addr;
-		else
-			return (ulong *)&_end;
 	}
+
+	return (ulong *)&_end;
 }
 
 int board_init(void)
Signature · 1 line
2.25.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 7 lines · Bin Meng

Commit 47d73ba4f4a4 ("board: sifive: overwrite board_fdt_blob_setup in u-boot proper") added a board-specific implementation of board_fdt_blob_setup() which takes a pointer as the return value, but it does not return anything
if CONFIG_OF_SEPARATE is not enabled. This will cause a build warning seen when testing booting S-mode U-Boot directly from QEMU, per the instructions in [1]:

Quoted 8 lines

board/sifive/unleashed/unleashed.c: In function ‘board_fdt_blob_setup’:
board/sifive/unleashed/unleashed.c:125:1: warning: control reaches end of non-void function [-Wreturn-type]

Return &_end as the default case.

[1] https://qemu.readthedocs.io/en/latest/system/riscv/sifive_u.html#running-u-boot

CONFIDENTIALITY NOTICE:

This e-mail (and its attachments) may contain confidential and legally privileged information or information protected from disclosure. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein is strictly prohibited. In this case, please immediately notify the sender by return e-mail, delete the message (and any accompanying documents) and destroy all printed hard copies. Thank you for your cooperation.

Copyright ANDES TECHNOLOGY CORPORATION - All Rights Reserved.

A message that is not in the archive (sent off-list or not yet received): HK0PR03MB299484FCB8C64939BB8F91E6C1DD9@HK0PR03MB2994.apcprd03.prod.outlook.com

Reviewed-by
#3 lore raw
Quoted 16 lines

From: Bin Meng <[email protected]>
Sent: Saturday, September 11, 2021 10:31 PM
To: Zong Li <[email protected]>; Leo Yu-Chi Liang(梁育齊) <[email protected]>; Rick Jian-Zhi Chen(陳建志) <[email protected]>; [email protected]
Subject: [PATCH v2] board: sifive: Fix a potential build warning in board_fdt_blob_setup()

Commit 47d73ba4f4a4 ("board: sifive: overwrite board_fdt_blob_setup in u-boot proper") added a board-specific implementation of board_fdt_blob_setup() which takes a pointer as the return value, but it does not return anything if CONFIG_OF_SEPARATE is not enabled. This will cause a build warning seen when testing booting S-mode U-Boot directly from QEMU, per the instructions in [1]:

board/sifive/unleashed/unleashed.c: In function ‘board_fdt_blob_setup’:
board/sifive/unleashed/unleashed.c:125:1: warning: control reaches end of non-void function [-Wreturn-type]

Return &_end as the default case.

[1] https://qemu.readthedocs.io/en/latest/system/riscv/sifive_u.html#running-u-boot

Quoted 7 lines

---

Changes in v2:
- Correct the commit title

 board/sifive/unleashed/unleashed.c | 4 ++--  board/sifive/unmatched/unmatched.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
author
#4 lore raw
Quoted 19 lines · Rick Chen
Quoted 19 lines

From: Bin Meng <[email protected]>
Sent: Saturday, September 11, 2021 10:31 PM
To: Zong Li <[email protected]>; Leo Yu-Chi Liang(梁育齊) <[email protected]>; Rick Jian-Zhi Chen(陳建志) <[email protected]>; [email protected]
Subject: [PATCH v2] board: sifive: Fix a potential build warning in board_fdt_blob_setup()

Commit 47d73ba4f4a4 ("board: sifive: overwrite board_fdt_blob_setup in u-boot proper") added a board-specific implementation of board_fdt_blob_setup() which takes a pointer as the return value, but it does not return anything if CONFIG_OF_SEPARATE is not enabled. This will cause a build warning seen when testing booting S-mode U-Boot directly from QEMU, per the instructions in [1]:

board/sifive/unleashed/unleashed.c: In function ‘board_fdt_blob_setup’:
board/sifive/unleashed/unleashed.c:125:1: warning: control reaches end of non-void function [-Wreturn-type]

Return &_end as the default case.

[1] https://qemu.readthedocs.io/en/latest/system/riscv/sifive_u.html#running-u-boot

---

Quoted 7 lines
Quoted 5 lines

Changes in v2:
- Correct the commit title

 board/sifive/unleashed/unleashed.c | 4 ++--  board/sifive/unmatched/unmatched.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

Ping for apply?

#5 lore raw
In reply to Bin Meng

Hi Bin

There's a similar discussion in a cleanup series I've sent [1]

Quoted 6 lines · Bin Meng

Commit 47d73ba4f4a4 ("board: sifive: overwrite board_fdt_blob_setup in u-boot proper") added a board-specific implementation of board_fdt_blob_setup() which takes a pointer as the return value, but it does not return anything
if CONFIG_OF_SEPARATE is not enabled. This will cause a build warning seen when testing booting S-mode U-Boot directly from QEMU, per the instructions in [1]:

It's not only a build warning, you don't even have a DTB to begin with.

Quoted 40 lines

board/sifive/unleashed/unleashed.c: In function ‘board_fdt_blob_setup’:
board/sifive/unleashed/unleashed.c:125:1: warning: control reaches end of non-void function [-Wreturn-type]

Return &_end as the default case.

[1] https://qemu.readthedocs.io/en/latest/system/riscv/sifive_u.html#running-u-boot

---

Changes in v2:
- Correct the commit title

 board/sifive/unleashed/unleashed.c | 4 ++--
 board/sifive/unmatched/unmatched.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
board/sifive/unleashed/unleashed.c +2 -2
index 8cd514df30..33baeda986 100644
@@ -119,9 +119,9 @@ void *board_fdt_blob_setup(void)
 	if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
 		if (gd->arch.firmware_fdt_addr)
 			return (ulong *)gd->arch.firmware_fdt_addr;
-		else
-			return (ulong *)&_end;
 	}
+
+	return (ulong *)&_end;
 }
 
 int board_init(void)
board/sifive/unmatched/unmatched.c +0 -0
index d90b252bae..8773b660fa 100644

board/sifive/unmatched/unmatched.c void *board_fdt_blob_setup(void) · line 21

Quoted 8 lines
board/sifive/unmatched/unmatched.c +2 -2
@@ -16,9 +16,9 @@ void *board_fdt_blob_setup(void)
 	if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
 		if (gd->arch.firmware_fdt_addr)
 			return (ulong *)gd->arch.firmware_fdt_addr;
-		else
-			return (ulong *)&_end;
 	}
+
+	return (ulong *)&_end;

is _end correct here? Doesn't the placement depend on CONFIG_SPL_BUILD and CONFIG_SPL_SEPARATE_BSS?

To sum up the other thread I think the overall approach here is not ideal. OF_SEPARATE is used in conjunction with SPL in these boards. What happens (assuming I didn't miss anything), is that SPL passes the DTB to OpenSBI, which in it turn copies to a1 before invoking U-Boot.
But we are better of with stricter rules for DTB.
- OF_SEPARATE means: I'll read the DTB from the U-Boot binary.
- OF_BOARD: The board will somehow provide it.

So II think the patch should look something along the lines of:

if (IS_ENABLED(CONFIG_OF_SEPARATE)) {

#ifdef CONFIG_SPL_BUILD
        /* FDT is at end of BSS unless it is in a different memory region */
        if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
                fdt_blob = (void *)&_image_binary_end;
        else
                fdt_blob = (void *)&__bss_end;
#else
        /* FDT is at end of image */
        fdt_blob = (void *)&_end;

}

if (IS_ENABLED(CONFIG_OF_BOARD)) {
	fdt_blob = (void *)gd->arch.firmware_fdt_addr;
}
Quoted 6 lines
board/sifive/unmatched/unmatched.c +0 -0
 }
 
 int board_init(void)
Signature · 1 line
2.25.1

[1] https://lore.kernel.org/u-boot/[email protected]/

Cheers
/Ilias

author
#6 lore raw

Hi Ilias,

Quoted 57 lines · Ilias Apalodimas

Hi Bin

There's a similar discussion in a cleanup series I've sent [1]

Quoted 6 lines · Bin Meng

Commit 47d73ba4f4a4 ("board: sifive: overwrite board_fdt_blob_setup in u-boot proper") added a board-specific implementation of board_fdt_blob_setup() which takes a pointer as the return value, but it does not return anything
if CONFIG_OF_SEPARATE is not enabled. This will cause a build warning seen when testing booting S-mode U-Boot directly from QEMU, per the instructions in [1]:

It's not only a build warning, you don't even have a DTB to begin with.

Quoted 43 lines

board/sifive/unleashed/unleashed.c: In function ‘board_fdt_blob_setup’:
board/sifive/unleashed/unleashed.c:125:1: warning: control reaches end of non-void function [-Wreturn-type]

Return &_end as the default case.

[1] https://qemu.readthedocs.io/en/latest/system/riscv/sifive_u.html#running-u-boot

---

Changes in v2:
- Correct the commit title

 board/sifive/unleashed/unleashed.c | 4 ++--
 board/sifive/unmatched/unmatched.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
board/sifive/unleashed/unleashed.c +2 -2
index 8cd514df30..33baeda986 100644
@@ -119,9 +119,9 @@ void *board_fdt_blob_setup(void)
      if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
              if (gd->arch.firmware_fdt_addr)
                      return (ulong *)gd->arch.firmware_fdt_addr;
-             else
-                     return (ulong *)&_end;
      }
+
+     return (ulong *)&_end;
 }
 
 int board_init(void)
board/sifive/unmatched/unmatched.c +0 -0
index d90b252bae..8773b660fa 100644
@@ -16,9 +16,9 @@ void *board_fdt_blob_setup(void)
      if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
              if (gd->arch.firmware_fdt_addr)
                      return (ulong *)gd->arch.firmware_fdt_addr;
Quoted 9 lines

board/sifive/unmatched/unmatched.c void *board_fdt_blob_setup(void) · line 21

Quoted 5 lines
board/sifive/unmatched/unmatched.c +2 -2
-             else
-                     return (ulong *)&_end;
      }
+
+     return (ulong *)&_end;

is _end correct here? Doesn't the placement depend on CONFIG_SPL_BUILD and CONFIG_SPL_SEPARATE_BSS?

I will have to leave this to Zong to comment as he introduced this via commit 47d73ba4f4a4 ("board: sifive: overwrite board_fdt_blob_setup in u-boot proper").

I don't know what user case that Zong wanted to support on Unleased and Unmatched.

Quoted 11 lines

To sum up the other thread I think the overall approach here is not ideal. OF_SEPARATE is used in conjunction with SPL in these boards. What happens (assuming I didn't miss anything), is that SPL passes the DTB to OpenSBI, which in it turn copies to a1 before invoking U-Boot.
But we are better of with stricter rules for DTB.
- OF_SEPARATE means: I'll read the DTB from the U-Boot binary.
- OF_BOARD: The board will somehow provide it.

So II think the patch should look something along the lines of:

if (IS_ENABLED(CONFIG_OF_SEPARATE)) {

Quoted 10 lines
#ifdef CONFIG_SPL_BUILD
        /* FDT is at end of BSS unless it is in a different memory region */
        if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
                fdt_blob = (void *)&_image_binary_end;
        else
                fdt_blob = (void *)&__bss_end;
#else
        /* FDT is at end of image */
        fdt_blob = (void *)&_end;

Missing #endif here?

Quoted 10 lines

}

if (IS_ENABLED(CONFIG_OF_BOARD)) {
        fdt_blob = (void *)gd->arch.firmware_fdt_addr;
}
Quoted 4 lines
board/sifive/unmatched/unmatched.c +0 -1
 }
 
 int board_init(void)
--

Regards,
Bin

#7 lore raw

[...]

Quoted 19 lines
Quoted 9 lines
Quoted 9 lines

int board_init(void)

board/sifive/unmatched/unmatched.c +0 -0
index d90b252bae..8773b660fa 100644
@@ -16,9 +16,9 @@ void *board_fdt_blob_setup(void)
      if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
              if (gd->arch.firmware_fdt_addr)
                      return (ulong *)gd->arch.firmware_fdt_addr;
Quoted 9 lines

board/sifive/unmatched/unmatched.c void *board_fdt_blob_setup(void) · line 21

Quoted 5 lines
board/sifive/unmatched/unmatched.c +2 -2
-             else
-                     return (ulong *)&_end;
      }
+
+     return (ulong *)&_end;

is _end correct here? Doesn't the placement depend on CONFIG_SPL_BUILD and CONFIG_SPL_SEPARATE_BSS?

Quoted 6 lines

I will have to leave this to Zong to comment as he introduced this via commit 47d73ba4f4a4 ("board: sifive: overwrite board_fdt_blob_setup in u-boot proper").

I don't know what user case that Zong wanted to support on Unleased and Unmatched.

Okay. The I think we can fix this correctly. We can probably use OF_BOARD in those boards, as long as the SPL generated DTB is always there and passed over to OpenSBI.

Quoted 23 lines
Quoted 12 lines

To sum up the other thread I think the overall approach here is not ideal. OF_SEPARATE is used in conjunction with SPL in these boards. What happens (assuming I didn't miss anything), is that SPL passes the DTB to OpenSBI, which in it turn copies to a1 before invoking U-Boot.
But we are better of with stricter rules for DTB.
- OF_SEPARATE means: I'll read the DTB from the U-Boot binary.
- OF_BOARD: The board will somehow provide it.

So II think the patch should look something along the lines of:

if (IS_ENABLED(CONFIG_OF_SEPARATE)) {

Quoted 10 lines
#ifdef CONFIG_SPL_BUILD
        /* FDT is at end of BSS unless it is in a different memory region */
        if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
                fdt_blob = (void *)&_image_binary_end;
        else
                fdt_blob = (void *)&__bss_end;
#else
        /* FDT is at end of image */
        fdt_blob = (void *)&_end;
Quoted 1 line

Missing #endif here?o

Yea it wasn't supposed to be real code.

Quoted 7 lines
Quoted 7 lines

}

if (IS_ENABLED(CONFIG_OF_BOARD)) {
        fdt_blob = (void *)gd->arch.firmware_fdt_addr;
}
Quoted 7 lines
Quoted 4 lines

board/sifive/unmatched/unmatched.c void *board_fdt_blob_setup(void)

Quoted 4 lines
board/sifive/unmatched/unmatched.c +0 -1
 }
 
 int board_init(void)
--

Regards,
Bin

Regards
/Ilias