RPi4B: an example of what RAM u-boot reserves during operation [patches updated]

Mark Millard marklmi at yahoo.com
Tue Oct 13 19:22:01 UTC 2020


On 2020-Oct-12, at 17:32, Mark Millard <marklmi at yahoo.com> wrote:

> On 2020-Oct-12, at 11:19, Mark Millard <marklmi at yahoo.com> wrote:
> 
>> . . .
> 
> U-Boot> bdinfo
> lmb_dump_all:
> . . .
>    reserved.cnt           = 0x2
>    reserved.size          = 0x0
>    reserved.reg[0x0].base = 0x0
>                     .size = 0x2000
>    reserved.reg[0x1].base = 0x3db47b30
>                     .size = 0x4b84d0
> . . .

The above does not cover as much as gonzo's old code
did during u-boot's time frame: the reserved space
was 0x4000 in size and that figure is supplied via x1
from argstub8-gic.bin code.

So the below is about having that reserve also covered
(during u-boot's time frame):

U-Boot> bdinfo
. . .
lmb_dump_all:
    . . .
    reserved.cnt           = 0x2
    reserved.size          = 0x0
    reserved.reg[0x0].base = 0x0
                     .size = 0x4000
    reserved.reg[0x1].base = 0x3db47b30
                     .size = 0x4b84d0
. . .

I doubt that the patches below are appropriate to upstream
in some respects. It is more targeted at being a
sysutils/u-boot-rpi[34] patch because what armstub8*.bin
supplies in x1 seems specific to the armstub8*.bin
FreeBSD uses.

I'll note that doing this has not changed the current
"rainbow stage hangup" when u-boot and modern firmware
are used together (usb not needing to be involved).

# more /usr/ports/sysutils/u-boot-rpi4/files/patch-board__raspberrypi__rpi__lowlevel_init.S 
--- board/raspberrypi/rpi/lowlevel_init.S.orig  2020-10-05 08:15:32.000000000 -0700
+++ board/raspberrypi/rpi/lowlevel_init.S       2020-10-13 11:33:39.273950000 -0700
@@ -18,9 +18,22 @@
 #ifdef CONFIG_ARM64
        adr     x8, fw_dtb_pointer
        str     x0, [x8]
+#if defined(CONFIG_EFI_LOADER)
+       /* Setup to allow reserving the stack and such that is */
+       /* after the likes of FreeBSD armstub8-gic.bin in RAM. */
+       adr     x8, armstub_rsrvd
+       str     x1, [x8]
+#endif
 #else
        ldr     r8, =fw_dtb_pointer
        str     r2, [r8]
+#if defined(CONFIG_EFI_LOADER)
+#error "Before aarch64 does not use armstub*.bin files"
+       /* Setup to allow reserving the stack and such that is */
+       /* after the likes of a armstub*.bin in RAM. */
+       ldr     r8, =armstub_rsrvd
+       str     r3, [r8]
+#endif
 #endif
 
        /* Returns */


# more /usr/ports/sysutils/u-boot-rpi4/files/patch-board__raspberrypi__rpi__rpi.c 
--- board/raspberrypi/rpi/rpi.c.orig    2020-10-05 08:15:32.000000000 -0700
+++ board/raspberrypi/rpi/rpi.c 2020-10-13 11:02:15.582706000 -0700
@@ -12,6 +12,7 @@
 #include <fdt_simplefb.h>
 #include <init.h>
 #include <lcd.h>
+#include <lmb.h>
 #include <memalign.h>
 #include <mmc.h>
 #include <asm/gpio.h>
@@ -33,6 +34,7 @@
  * does not get cleared later.
  */
 unsigned long __section(".data") fw_dtb_pointer;
+unsigned long __section(".data") armstub_rsrvd;
 
 /* TODO(sjg at chromium.org): Move these to the msg.c file */
 struct msg_get_arm_mem {
@@ -494,4 +496,29 @@
 #endif
 
        return 0;
+}
+
+void board_lmb_reserve(struct lmb *lmb)
+{
+#ifdef CONFIG_EFI_LOADER
+       /*
+        * NOTE: lmb_reserve (and more) does not deal with overlaps with
+        *       pre-existing reservations.
+        *       But board_lmb_reserve is called before the original
+        *       first-page is added. So use knowledge of what will happen
+        *       later to avoid overlaps.
+        */
+
+       phys_addr_t base = 0x0u;
+       phys_addr_t size = CONFIG_RPI_EFI_NR_SPIN_PAGES << EFI_PAGE_SHIFT;
+       if (size < armstub_rsrvd) size = armstub_rsrvd;
+
+       if (size <= EFI_PAGE_SIZE) return;
+
+       /* Avoid future overlap */
+       base += EFI_PAGE_SIZE;
+       size -= EFI_PAGE_SIZE;
+
+       lmb_reserve(lmb, base, size);
+#endif
 }


===
Mark Millard
marklmi at yahoo.com
( dsl-only.net went
away in early 2018-Mar)



More information about the freebsd-arm mailing list