All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] riscv: cv1800b: Milk-V Duo boot fixes
@ 2026-09-30 12:17 Hiago De Franco
  2026-09-30 12:17 ` [PATCH 1/2] board: sophgo: milkv_duo_256m: fix fdtfile quoting Hiago De Franco
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Hiago De Franco @ 2026-09-30 12:17 UTC (permalink / raw)
  To: Leo Yu-Chi Liang, u-boot, Yao Zi
  Cc: Tom Rini, Tim Ouyang, Zhuxu Ran, Kongyang Liu

This series fixes two problems on the Sophgo CV1800B/SG2002 Milk-V Duo
boards.

Patch 1 fixes the fdtfile environment variable of the Milk-V Duo 256M.
CONFIG_DEFAULT_DEVICE_TREE is a quoted string, so the quotes ended up
in the environment.

Patch 2 keeps U-Boot out of the memory reserved for the coprocessor
firmware. The upstream devicetrees reserve the end of DRAM as a no-map
region, but U-Boot relocates to ram_top, which is the end of DRAM, so
it lands inside that region.

This was tested on both Milk-V Duo 64M and 256M (CV1800B and SG2002).

Signed-off-by: Hiago De Franco <hfranco@baylibre.com>
---
Hiago De Franco (2):
      board: sophgo: milkv_duo_256m: fix fdtfile quoting
      riscv: cpu: cv1800b: keep U-Boot out of reserved memory

 arch/riscv/cpu/cv1800b/dram.c                  | 25 +++++++++++++++++++++++++
 board/sophgo/milkv_duo_256m/milkv_duo_256m.env |  2 +-
 2 files changed, 26 insertions(+), 1 deletion(-)
---
base-commit: f8eb3469e1a17c79b047b3fd38ae820e8816a115
change-id: 20260929-256m-fixes-919700ca762f
prerequisite-change-id: 20260702-milkv-duo-upstream-dts-b54aed41fc61:v5
prerequisite-patch-id: b8e6815314b7881a02de0066232864d522c4a26c
prerequisite-patch-id: 0df1fa5db1b2bff402b429809796bad99a517483
prerequisite-patch-id: 49e1e8263cf0a5ba8d63c8b598b6382cde5284b2
prerequisite-patch-id: 86dd30e784f022f0a7bb6fbf125c9699467176d4
prerequisite-patch-id: 49070c05ecf58331ec519a57d1b82f8b2b835a89
prerequisite-patch-id: 6b6881e45cc6de6544aaa4509db21611158f4fa1
prerequisite-patch-id: 7198127d4602eeb14212087ce9bb694d84e71a4c
prerequisite-patch-id: 3a58bd8a061707ff27b8538d4897def3b595dc36
prerequisite-patch-id: 9055ea941b73e35d1e825787d7eca14ffceb8e8b
prerequisite-patch-id: 554c1487e8d596e0099677ca88eee0021b1ffbae

Best regards,
--  
Hiago


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] board: sophgo: milkv_duo_256m: fix fdtfile quoting
  2026-09-30 12:17 [PATCH 0/2] riscv: cv1800b: Milk-V Duo boot fixes Hiago De Franco
@ 2026-09-30 12:17 ` Hiago De Franco
  2026-09-30 12:17 ` [PATCH 2/2] riscv: cpu: cv1800b: keep U-Boot out of reserved memory Hiago De Franco
  2026-10-07 21:48 ` [PATCH 0/2] riscv: cv1800b: Milk-V Duo boot fixes Yao Zi
  2 siblings, 0 replies; 7+ messages in thread
From: Hiago De Franco @ 2026-09-30 12:17 UTC (permalink / raw)
  To: Leo Yu-Chi Liang, u-boot, Yao Zi
  Cc: Tom Rini, Tim Ouyang, Zhuxu Ran, Kongyang Liu

CONFIG_DEFAULT_DEVICE_TREE is a quoted string, so the quotes end up in
the environment:

  fdtfile="sg2002-milkv-duo256m".dtb

Use DEFAULT_DEVICE_TREE instead, which the build passes to the
environment preprocessor without the quotes:

  fdtfile=sophgo/sg2002-milkv-duo256m.dtb

Fixes: 98b59e181daa ("board: sophgo: add support for Milk-V Duo 256M")
Signed-off-by: Hiago De Franco <hfranco@baylibre.com>
---
 board/sophgo/milkv_duo_256m/milkv_duo_256m.env | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/board/sophgo/milkv_duo_256m/milkv_duo_256m.env b/board/sophgo/milkv_duo_256m/milkv_duo_256m.env
index 4c1e17b53ca..4c9f53d0811 100644
--- a/board/sophgo/milkv_duo_256m/milkv_duo_256m.env
+++ b/board/sophgo/milkv_duo_256m/milkv_duo_256m.env
@@ -1,5 +1,5 @@
 fdt_addr_r=0x84000000
-fdtfile=CONFIG_DEFAULT_DEVICE_TREE.dtb
+fdtfile=DEFAULT_DEVICE_TREE.dtb
 kernel_addr_r=0x80200000
 kernel_comp_addr_r=0x88000000
 kernel_comp_size=0x4000000

-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] riscv: cpu: cv1800b: keep U-Boot out of reserved memory
  2026-09-30 12:17 [PATCH 0/2] riscv: cv1800b: Milk-V Duo boot fixes Hiago De Franco
  2026-09-30 12:17 ` [PATCH 1/2] board: sophgo: milkv_duo_256m: fix fdtfile quoting Hiago De Franco
@ 2026-09-30 12:17 ` Hiago De Franco
  2026-10-07 21:46   ` Yao Zi
  2026-10-07 21:48 ` [PATCH 0/2] riscv: cv1800b: Milk-V Duo boot fixes Yao Zi
  2 siblings, 1 reply; 7+ messages in thread
From: Hiago De Franco @ 2026-09-30 12:17 UTC (permalink / raw)
  To: Leo Yu-Chi Liang, u-boot, Yao Zi
  Cc: Tom Rini, Tim Ouyang, Zhuxu Ran, Kongyang Liu

The upstream devicetrees reserve the end of DRAM for the coprocessor
firmware, as a no-map region:

  cv1800b-milkv-duo:    region@83f40000, size 0xc0000
  sg2002-milkv-duo256m: region@8fe00000, size 0x200000

ram_top is the end of DRAM, so U-Boot relocates into that region. On the
Milk-V Duo, relocaddr is 0x83f76000, and LMB then fails to reserve the
region:

ERROR: reserving fdt memory region failed (addr=83f40000 size=c0000
flags=2): -17

Implement board_get_usable_ram_top() with get_mem_top(), which returns
the highest free window below the devicetree reserved regions, as the
Xilinx boards do.

Signed-off-by: Hiago De Franco <hfranco@baylibre.com>
---
 arch/riscv/cpu/cv1800b/dram.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/arch/riscv/cpu/cv1800b/dram.c b/arch/riscv/cpu/cv1800b/dram.c
index 5d7659887b9..abcc239a289 100644
--- a/arch/riscv/cpu/cv1800b/dram.c
+++ b/arch/riscv/cpu/cv1800b/dram.c
@@ -3,10 +3,14 @@
  * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
  */
 
+#include <asm/global_data.h>
 #include <fdtdec.h>
 #include <init.h>
+#include <memtop.h>
 #include <linux/sizes.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 int dram_init(void)
 {
 	return fdtdec_setup_mem_size_base();
@@ -16,3 +20,24 @@ int dram_init_banksize(void)
 {
 	return fdtdec_setup_memory_banksize();
 }
+
+phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
+{
+	phys_size_t size;
+	phys_addr_t reg;
+
+	if (!total_size)
+		return gd->ram_top;
+
+	/*
+	 * The coprocessor firmware is reserved at the end of DRAM, keep
+	 * U-Boot out of it and of any other reserved region.
+	 */
+	size = ALIGN(CONFIG_SYS_MALLOC_LEN + total_size, SZ_1M);
+	reg = get_mem_top(gd->ram_base, gd->ram_size, size,
+			  (void *)gd->fdt_blob);
+	if (!reg)
+		return gd->ram_top;
+
+	return reg + size;
+}

-- 
2.53.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/2] riscv: cpu: cv1800b: keep U-Boot out of reserved memory
  2026-09-30 12:17 ` [PATCH 2/2] riscv: cpu: cv1800b: keep U-Boot out of reserved memory Hiago De Franco
@ 2026-10-07 21:46   ` Yao Zi
  0 siblings, 0 replies; 7+ messages in thread
From: Yao Zi @ 2026-10-07 21:46 UTC (permalink / raw)
  To: Hiago De Franco, Leo Yu-Chi Liang, u-boot, Yao Zi
  Cc: Tom Rini, Tim Ouyang, Zhuxu Ran, Kongyang Liu

On Wed, Sep 30, 2026 at 09:17:50AM -0300, Hiago De Franco wrote:
> The upstream devicetrees reserve the end of DRAM for the coprocessor
> firmware, as a no-map region:
> 
>   cv1800b-milkv-duo:    region@83f40000, size 0xc0000
>   sg2002-milkv-duo256m: region@8fe00000, size 0x200000
> 
> ram_top is the end of DRAM, so U-Boot relocates into that region. On the
> Milk-V Duo, relocaddr is 0x83f76000, and LMB then fails to reserve the
> region:
> 
> ERROR: reserving fdt memory region failed (addr=83f40000 size=c0000
> flags=2): -17
> 
> Implement board_get_usable_ram_top() with get_mem_top(), which returns
> the highest free window below the devicetree reserved regions, as the
> Xilinx boards do.

You might already notice this series[1] removing co-processor-related
reserved regions from the upstream devicetree, which, in my opinion, is
the correct way to go (and actually suggested by myself), since the
code occupying a memory region should take the responsibility to reserve
it.

So issues being solved here might simply go away in the future, it might
be useful to add the context that this is a temporary workaround.

The other way to go is simply removing the reserved region from the
U-Boot devicetree. IIRC the vendor FSBL doesn't load any co-processor
firmware unless you package one into the fip.bin.

Regards,
Yao Zi

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] riscv: cv1800b: Milk-V Duo boot fixes
  2026-09-30 12:17 [PATCH 0/2] riscv: cv1800b: Milk-V Duo boot fixes Hiago De Franco
  2026-09-30 12:17 ` [PATCH 1/2] board: sophgo: milkv_duo_256m: fix fdtfile quoting Hiago De Franco
  2026-09-30 12:17 ` [PATCH 2/2] riscv: cpu: cv1800b: keep U-Boot out of reserved memory Hiago De Franco
@ 2026-10-07 21:48 ` Yao Zi
  2026-10-09 14:31   ` Hiago De Franco
  2 siblings, 1 reply; 7+ messages in thread
From: Yao Zi @ 2026-10-07 21:48 UTC (permalink / raw)
  To: Hiago De Franco, Leo Yu-Chi Liang, u-boot, Yao Zi
  Cc: Tom Rini, Tim Ouyang, Zhuxu Ran, Kongyang Liu

On Wed, Sep 30, 2026 at 09:17:48AM -0300, Hiago De Franco wrote:
> This series fixes two problems on the Sophgo CV1800B/SG2002 Milk-V Duo
> boards.
> 
> Patch 1 fixes the fdtfile environment variable of the Milk-V Duo 256M.
> CONFIG_DEFAULT_DEVICE_TREE is a quoted string, so the quotes ended up
> in the environment.
> 
> Patch 2 keeps U-Boot out of the memory reserved for the coprocessor
> firmware. The upstream devicetrees reserve the end of DRAM as a no-map
> region, but U-Boot relocates to ram_top, which is the end of DRAM, so
> it lands inside that region.

I think the issue solved by PATCH 2 is introduced during switching to
upstream devicetree? Could you please cooperate with Zhuxu so nothing
is broken at the first place? Thanks.

Regards,
Yao Zi

> This was tested on both Milk-V Duo 64M and 256M (CV1800B and SG2002).
> 
> Signed-off-by: Hiago De Franco <hfranco@baylibre.com>
> ---
> Hiago De Franco (2):
>       board: sophgo: milkv_duo_256m: fix fdtfile quoting
>       riscv: cpu: cv1800b: keep U-Boot out of reserved memory

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] riscv: cv1800b: Milk-V Duo boot fixes
  2026-10-07 21:48 ` [PATCH 0/2] riscv: cv1800b: Milk-V Duo boot fixes Yao Zi
@ 2026-10-09 14:31   ` Hiago De Franco
  2026-10-11  7:23     ` Zhuxu Ran
  0 siblings, 1 reply; 7+ messages in thread
From: Hiago De Franco @ 2026-10-09 14:31 UTC (permalink / raw)
  To: Yao Zi
  Cc: Leo Yu-Chi Liang, u-boot, Tom Rini, Tim Ouyang, Zhuxu Ran,
	Kongyang Liu

Hello,

On Wed, Oct 07, 2026 at 09:48:59PM +0000, Yao Zi wrote:
> On Wed, Sep 30, 2026 at 09:17:48AM -0300, Hiago De Franco wrote:
> > This series fixes two problems on the Sophgo CV1800B/SG2002 Milk-V Duo
> > boards.
> > 
> > Patch 1 fixes the fdtfile environment variable of the Milk-V Duo 256M.
> > CONFIG_DEFAULT_DEVICE_TREE is a quoted string, so the quotes ended up
> > in the environment.
> > 
> > Patch 2 keeps U-Boot out of the memory reserved for the coprocessor
> > firmware. The upstream devicetrees reserve the end of DRAM as a no-map
> > region, but U-Boot relocates to ram_top, which is the end of DRAM, so
> > it lands inside that region.
> 
> I think the issue solved by PATCH 2 is introduced during switching to
> upstream devicetree? Could you please cooperate with Zhuxu so nothing
> is broken at the first place? Thanks.

Thanks for the review, you are right. The issue only shows up once the
boards switch to the upstream devicetrees from Zhuxu's series, and
Andrei's patches that drop the coprocessor reserved-memory nodes are
already in the Sophgo tree for linux-next:

  6645398c4621 ("riscv: dts: sophgo: cv1800b-milkv-duo: drop reserved memory node")
  60e4cafd3090 ("riscv: dts: sophgo: sg2002-milkv-duo256m: drop reserved memory node")

I tested Zhuxu's v5 plus these two commits applied to dts/upstream,
without my patch 2, on both Milk-V Duo 64M and 256M. The reserved memory
error is gone and U-Boot relocates to the top of DRAM as before:

  Duo 64M:  relocaddr = 0x83f79000
  Duo 256M: relocaddr = 0x8ff6e000

So I will drop patch 2 and send a v2 with only the fdtfile fix.

Zhuxu (Cc'd), to avoid breaking these boards in between, could you carry
those two devicetree changes in your series, or should we wait for the
next dts/upstream sync that includes them before your series is merged?

> 
> Regards,
> Yao Zi
> 
> > This was tested on both Milk-V Duo 64M and 256M (CV1800B and SG2002).
> > 
> > Signed-off-by: Hiago De Franco <hfranco@baylibre.com>
> > ---
> > Hiago De Franco (2):
> >       board: sophgo: milkv_duo_256m: fix fdtfile quoting
> >       riscv: cpu: cv1800b: keep U-Boot out of reserved memory

Best regards,
-- 
Hiago

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/2] riscv: cv1800b: Milk-V Duo boot fixes
  2026-10-09 14:31   ` Hiago De Franco
@ 2026-10-11  7:23     ` Zhuxu Ran
  0 siblings, 0 replies; 7+ messages in thread
From: Zhuxu Ran @ 2026-10-11  7:23 UTC (permalink / raw)
  To: Hiago De Franco, Yao Zi
  Cc: Leo Yu-Chi Liang, u-boot, Tom Rini, Tim Ouyang, Zhuxu Ran,
	Kongyang Liu

Hi Hiago,

Thanks for testing this and for identifying the dependency. I also
reproduced the reserved-memory error on Milk-V Duo 64M with my v5 series.

I would prefer to wait for the next dts/upstream sync that includes
Andrei's two changes before the migration series is merged. Once the
sync lands, I will rebase the series as needed and retest the boards.

-- 
Best regards,
Zhuxu Ran


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-10-11 14:39 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-30 12:17 [PATCH 0/2] riscv: cv1800b: Milk-V Duo boot fixes Hiago De Franco
2026-09-30 12:17 ` [PATCH 1/2] board: sophgo: milkv_duo_256m: fix fdtfile quoting Hiago De Franco
2026-09-30 12:17 ` [PATCH 2/2] riscv: cpu: cv1800b: keep U-Boot out of reserved memory Hiago De Franco
2026-10-07 21:46   ` Yao Zi
2026-10-07 21:48 ` [PATCH 0/2] riscv: cv1800b: Milk-V Duo boot fixes Yao Zi
2026-10-09 14:31   ` Hiago De Franco
2026-10-11  7:23     ` Zhuxu Ran

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.