Re: [PATCH v3 4/7] riscv: milkv_duo: Use upstream devicetree

Andrei Lalaev <[email protected]>
Newsgroups org.u-boot-project.lists.u-boot
Message-ID <[email protected]>
Hi Zhuxu,

Thank you for your patches.

I am playing with Duo and Duo-256M and faced an interesting thing
regarding reserved-memory on these boards.

It looks like your patchset may cause a memory corruption
of U-Boot or coprocessor FW for Milk-V Duo.

DTS in U-Boot limits RAM to 63.25 MB:

  memory@80000000 {
          device_type = "memory";
          reg = <0x80000000 0x3f40000>;
  };

Because the last 0.75 MB (0xc0000) is reserved for coprocessor.
Kernel uses different approach by declaring all RAM and
relying on `reserved-memory` for coprocessor.

However, this doesn't work for U-Boot because it places its stack
and heap near the top of RAM, therefore region in the top of RAM
is not reserved. So coprocessor FW or U-Boot may be corrupted.

With your patches it also gives an ERROR during reserving (because the region
is already used by U-Boot itself):

  U-Boot 2026.10-rc3-00007-g8e48ce755361 (Aug 27 2026 - 18:53:59 +0200)milkv_duo

  DRAM:  64 MiB
  ERROR: reserving fdt memory region failed (addr=83f40000 size=c0000 flags=2): -17
  Core:  23 devices, 15 uclasses, devicetree: separate
  MMC:   mmc@4310000: 0
  Loading Environment from nowhere... OK
  In:    serial@4140000
  Out:   serial@4140000
  Err:   serial@4140000
  Net:
  Warning: ethernet@4070000 (eth0) using random MAC address - 0a:06:39:79:c7:ed
  eth0: ethernet@4070000

  milkv_duo# bdinfo
  boot_params = 0x0000000000000000
  DRAM bank   = 0x0000000000000000
  -> start    = 0x0000000080000000
  -> size     = 0x0000000004000000
     ...
  relocaddr   = 0x0000000083f73000
  reloc off   = 0x0000000003d73000
     ...
  fdt_blob    = 0x000000008372ec60
  lmb_dump_all:
   memory.count = 0x1
   memory[0]      [0x80000000-0x83ffffff], 0x4000000 bytes, flags: none
   reserved.count = 0x3
   reserved[0]    [0x80000000-0x8005ffff], 0x60000 bytes, flags: no-map
   reserved[1]    [0x8272b000-0x8272dfff], 0x3000 bytes, flags: no-notify, no-overwrite
   reserved[2]    [0x8272ec50-0x83ffffff], 0x18d13b0 bytes, flags: no-overwrite
  devicetree  = separate
     ...
  stack ptr   = 0x000000008372e980
  ram_top ptr = 0x0000000084000000
  malloc base = 0x0000000083733000
  boot hart   = 0x0000000000000000
  firmware fdt= 0x0000000080080000

  milkv_duo# meminfo
  DRAM:  64 MiB

  Region                Base          Size           End           Gap
  --------------------------------------------------------------------
  code              83f73000         8cc30      83fffc30
  malloc            83733000        840000      83f73000             0
  board_info        83732fb0            50      83733000             0
  global_data       83732e40           168      83732fa8             8
  devicetree        8372ec60          41da      83732e3a             6
  stack             8272ec50       1000000      8372ec50            10
  lmb               8272ec50             0      8272ec50             0
  lmb               8272b000          3c50      8272ec50             0
  lmb               80000000       272b000      8272b000             0
  free              80000000             0      80000000             0


Main branch with the original U-Boot DTS:
  U-Boot 2026.10-rc3-00001-g7cbe3e32b6b4 (Aug 27 2026 - 18:30:42 +0200)milkv_duo

  DRAM:  63.3 MiB
  Core:  22 devices, 15 uclasses, devicetree: separate
  MMC:   mmc@4310000: 0
  Loading Environment from nowhere... OK
  In:    serial@4140000
  Out:   serial@4140000
  Err:   serial@4140000
  Net:
  Warning: ethernet@4070000 (eth0) using random MAC address - 82:8a:04:d3:35:d0
  eth0: ethernet@4070000

  milkv_duo# bdinfo
  boot_params = 0x0000000000000000
  DRAM bank   = 0x0000000000000000
  -> start    = 0x0000000080000000
  -> size     = 0x0000000003f40000
     ...
  relocaddr   = 0x0000000083eb3000
  reloc off   = 0x0000000003cb3000
     ...
  fdt_blob    = 0x00000000836705e0
  lmb_dump_all:
   memory.count = 0x1
   memory[0]      [0x80000000-0x83f3ffff], 0x3f40000 bytes, flags: none
   reserved.count = 0x3
   reserved[0]    [0x80000000-0x8005ffff], 0x60000 bytes, flags: no-map
   reserved[1]    [0x8266d000-0x8266ffff], 0x3000 bytes, flags: no-notify, no-overwrite
   reserved[2]    [0x826705d0-0x83f3ffff], 0x18cfa30 bytes, flags: no-overwrite
  devicetree  = separate
     ...
  stack ptr   = 0x0000000083670300
  ram_top ptr = 0x0000000083f40000
  malloc base = 0x0000000083673000
  boot hart   = 0x0000000000000000
  firmware fdt= 0x0000000080080000


I'm not sure of a better solution here other than limiting the RAM node
to exclude the coprocessor region.

Best regards,
Andrei Lalaev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.