Skip to contentSkip to conversation

Support booting modern EDK2 on raspi3b board

PATCH New [email protected] 1 participant 5 messages Aug 19

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Support booting modern EDK2 on raspi3b board

From: Frederik van Hövell <[email protected]>

This series fixes raspi3b board behaviour when using EDK2 firmware:
- fix framebuffer base response: firmware (and linux kernel) expects returned address as seen from VC4 GPU memory view.
- fix firmware revision response: EDK2 firmware expects a valid epoch timestamp after year 2000, where previous used value was far too old.

NB: Due to incomplete emulation it does not yet work for raspi4b (missing RNG200 and GENETv5, amongst other issues).

As convenience it fixes starting raspi3ap, raspi3b and raspi4b boards with firmware using '-bios RPI_EFI.fd' (as was already possible using '-loader file=RPI_EFI.fd,force-raw=true').

Finally it adds an functional test for running EDK2 firmware using new parameter -bios on raspi3b and bumps RPi3 EDK2 release to latest v1.52.

Frederik van Hövell (4):
hw/misc/bcm2835_property: fix RPI_FWREQ_FRAMEBUFFER_ALLOCATE response hw/misc/bcm2835_property: fix RPI_FWREQ_GET_FIRMWARE_REVISION response hw/arm/raspi: implement booting firmware at 0x0 using -bios on boards

    3ap, 3b and 4b

tests/functional/aarch64/test_raspi3: update firmware to v1.52

 docs/system/arm/raspi.rst               | 12 ++++++++++++
 hw/arm/raspi.c                          | 17 +++++++++++------
 hw/misc/bcm2835_property.c              |  6 ++++--
 include/hw/display/bcm2835_fb.h         |  3 ++-
 tests/functional/aarch64/test_raspi3.py | 18 +++++++++++++++---
 5 files changed, 44 insertions(+), 12 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/4 hw/misc/bcm2835_property: fix RPI_FWREQ_FRAMEBUFFER_ALLOCATE response

From: Frederik van Hövell <[email protected]>

The value is used as framebuffer base address, but seen from the VideoCore[4-6] processor view of memory.
This GPU view uses an offset of 0xc0000000 (i.e. bits 30 and 31 always set to 1), compared to the CPU memory view.
Above interpretation can be found in below kernels:
- UEFI firmware [edk2-platforms](https://github.com/tianocore/edk2-platforms/blob/306137738faf9f31eba9823d0f818397755cedaf/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c#L1045)
- [Upstream linux](https://github.com/torvalds/linux/blob/0031c06807cfa8aa51a759ff8aa09e1aa48149af/drivers/gpu/drm/vc4/vc4_drv.c#L312)
- [RaspberryPi linux](https://github.com/raspberrypi/linux/blob/3e44c7fdf879208adf51be589d60962269d25d18/drivers/video/fbdev/bcm2708_fb.c#L464C1-L466C29)

---
 hw/misc/bcm2835_property.c      | 3 ++-
 include/hw/display/bcm2835_fb.h | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
hw/misc/bcm2835_property.c +2 -1
index 216a746c2bd..a90c7e6c863 100644
@@ -168,7 +168,8 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
         /* Frame buffer */
 
         case RPI_FWREQ_FRAMEBUFFER_ALLOCATE:
-            stl_le_phys(&s->dma_as, value + 12, fbconfig.base);
+            stl_le_phys(&s->dma_as, value + 12,
+                        fbconfig.base | BCM2836_DMA_DEVICE_OFFSET);
             stl_le_phys(&s->dma_as, value + 16,
                         bcm2835_fb_get_size(&fbconfig));
             resplen = 8;
include/hw/display/bcm2835_fb.h +2 -1
index f7ef076f1f4..bcc87ad5390 100644
@@ -15,7 +15,8 @@
 #include "hw/core/sysbus.h"
 #include "qom/object.h"
 
-#define UPPER_RAM_BASE 0x40000000
+#define UPPER_RAM_BASE            0x40000000
+#define BCM2836_DMA_DEVICE_OFFSET 0xc0000000
 
 #define TYPE_BCM2835_FB "bcm2835-fb"
 OBJECT_DECLARE_SIMPLE_TYPE(BCM2835FBState, BCM2835_FB)
Signature · 1 line
2.55.0
#2 lore raw

PATCH 2/4 hw/misc/bcm2835_property: fix RPI_FWREQ_GET_FIRMWARE_REVISION response

In reply to [email protected]

From: Frederik van Hövell <[email protected]>

The returned value for revision is interpreted as an unix epoch timestamp after year 2000 by EDK2 for RPi3/4 boards. EDK2 firmware uses the revision to show as human-readable 'year.month', and asserted to have year between 2000 and 2255 (both inclusive).

See [PlatformSmbiosDxe.c](https://github.com/tianocore/edk2-platforms/blob/master/Platform/RaspberryPi/Drivers/PlatformSmbiosDxe/PlatformSmbiosDxe.c#L763).

---
 hw/misc/bcm2835_property.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/misc/bcm2835_property.c +2 -1
index a90c7e6c863..a705e44b1fe 100644
@@ -52,7 +52,8 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
         case RPI_FWREQ_PROPERTY_END:
             break;
         case RPI_FWREQ_GET_FIRMWARE_REVISION:
-            stl_le_phys(&s->dma_as, value + 12, 346337);
+            // Use timestamp of first released Raspberry Pi as minimum 'revision': 2012-02-29T00:00:00.000Z
+            stl_le_phys(&s->dma_as, value + 12, 1330473600);
             resplen = 4;
             break;
         case RPI_FWREQ_GET_BOARD_MODEL:
Signature · 1 line
2.55.0
#3 lore raw

PATCH 3/4 hw/arm/raspi: implement booting firmware at 0x0 using -bios on boards 3ap, 3b and 4b

In reply to [email protected]

From: Frederik van Hövell <[email protected]>

---
 docs/system/arm/raspi.rst               | 12 ++++++++++++
 hw/arm/raspi.c                          | 17 +++++++++++------
 tests/functional/aarch64/test_raspi3.py | 12 ++++++++++++
 3 files changed, 35 insertions(+), 6 deletions(-)
docs/system/arm/raspi.rst +12 -0
index 44eec3f1c33..fb912da129b 100644
@@ -43,3 +43,15 @@ Missing devices
  * Pulse Width Modulation (PWM)
  * PCIE Root Port (raspi4b)
  * GENET Ethernet Controller (raspi4b)
+
+Boot options
+------------
+
+The Raspberry Pi models support booting via either a Linux kernel (``-kernel``)
+or UEFI/EDK2 firmware images (``-bios rpi_efi.fd``).
+
+When booting Raspberry Pi 3 (``raspi3b``, ``raspi3ap``) and Raspberry Pi 4 (``raspi4b``)
+boards with EDK2 firmware via ``-bios``, the firmware image is loaded at physical
+memory address ``0x0``, matching the platform expectations. Older 32-bit models
+(``raspi0``, ``raspi1ap``, ``raspi2b``) load firmware at their respective legacy addresses
+(``0x8000``).
hw/arm/raspi.c +11 -6
index 3f99e87428c..c0b177f8cb1 100644
@@ -33,8 +33,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(RaspiMachineState, RASPI_MACHINE)
 #define SMPBOOT_ADDR    0x300 /* this should leave enough space for ATAGS */
 #define MVBAR_ADDR      0x400 /* secure vectors */
 #define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20) /* board setup code */
-#define FIRMWARE_ADDR_2 0x8000 /* Pi 2 loads kernel.img here by default */
-#define FIRMWARE_ADDR_3 0x80000 /* Pi 3 loads kernel.img here by default */
+#define KERNEL_ADDR_PI2 0x8000 /* Pi 2 loads kernel.img here by default */
 #define SPINTABLE_ADDR  0xd8 /* Pi 3 bootloader spintable */
 
 struct RaspiMachineState {
@@ -193,7 +192,7 @@ static void setup_boot(MachineState *machine, ARMCPU *cpu,
                        RaspiProcessorId processor_id, size_t ram_size)
 {
     RaspiBaseMachineState *s = RASPI_BASE_MACHINE(machine);
-    int r;
+    ssize_t r;
 
     s->binfo.ram_size = ram_size;
 
@@ -226,9 +225,15 @@ static void setup_boot(MachineState *machine, ARMCPU *cpu,
      * the normal Linux boot process
      */
     if (machine->firmware) {
-        hwaddr firmware_addr = processor_id <= PROCESSOR_ID_BCM2836
-                             ? FIRMWARE_ADDR_2 : FIRMWARE_ADDR_3;
-        /* load the firmware image (typically kernel.img) */
+        hwaddr firmware_addr;
+        if (processor_id <= PROCESSOR_ID_BCM2836) {
+            // For RPi 0/1/2 (arm, 32 bit mode) support kernel.img loading at default address
+            firmware_addr = KERNEL_ADDR_PI2;
+        } else {
+            // For RPi 3 or newer boards (aarch64), support edk2 firmware
+            firmware_addr = 0x0;
+        }
+        /* Load the firmware image (typically kernel.img or edk2 firmware) */
         r = load_image_targphys(machine->firmware, firmware_addr,
                                 ram_size - firmware_addr, NULL);
         if (r < 0) {
tests/functional/aarch64/test_raspi3.py +12 -0
index ae9eed3589f..709c7221fa4 100755
@@ -29,6 +29,18 @@ def test_aarch64_raspi3_atf(self):
         self.vm.launch()
         self.wait_for_console_pattern('version UEFI Firmware v1.15')
 
+    def test_aarch64_raspi3_bios(self):
+        efi_name = 'RPI_EFI.fd'
+        efi_fd = self.archive_extract(self.ASSET_RPI3_UEFI, member=efi_name)
+
+        self.set_machine('raspi3b')
+        self.vm.set_console(console_index=1)
+        self.vm.add_args('-cpu', 'cortex-a53',
+                         '-nodefaults',
+                         '-bios', efi_fd)
+        self.vm.launch()
+        self.wait_for_console_pattern('version UEFI Firmware v1.15')
+
 
 if __name__ == '__main__':
     LinuxKernelTest.main()
Signature · 1 line
2.55.0
#4 lore raw

PATCH 4/4 tests/functional/aarch64/test_raspi3: update firmware to v1.52

In reply to [email protected]

From: Frederik van Hövell <[email protected]>

---
 tests/functional/aarch64/test_raspi3.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
tests/functional/aarch64/test_raspi3.py +4 -4
index 709c7221fa4..ffc6f2517fd 100755
@@ -14,8 +14,8 @@ class Aarch64Raspi3Machine(LinuxKernelTest):
 
     ASSET_RPI3_UEFI = Asset(
         ('https://github.com/pbatard/RPi3/releases/download/'
-         'v1.15/RPi3_UEFI_Firmware_v1.15.zip'),
-        '8cff2e979560048b4c84921f41a91893240b9fb71a88f0b5c5d6c8edd994bd5b')
+         'v1.52/RPi3_UEFI_Firmware_v1.52.zip'),
+        '20b894d15cdb42e055872a7ee6a850aa9373aedcfefd27f19767d975ce4f7371')
 
     def test_aarch64_raspi3_atf(self):
         efi_name = 'RPI_EFI.fd'
@@ -27,7 +27,7 @@ def test_aarch64_raspi3_atf(self):
                          '-nodefaults',
                          '-device', f'loader,file={efi_fd},force-raw=true')
         self.vm.launch()
-        self.wait_for_console_pattern('version UEFI Firmware v1.15')
+        self.wait_for_console_pattern('version UEFI Firmware v1.52')
 
     def test_aarch64_raspi3_bios(self):
         efi_name = 'RPI_EFI.fd'
@@ -39,7 +39,7 @@ def test_aarch64_raspi3_bios(self):
                          '-nodefaults',
                          '-bios', efi_fd)
         self.vm.launch()
-        self.wait_for_console_pattern('version UEFI Firmware v1.15')
+        self.wait_for_console_pattern('version UEFI Firmware v1.52')
 
 
 if __name__ == '__main__':
Signature · 1 line
2.55.0