rpi4: Accommodate "armstub8.bin" header at the beginning of BL31 image
[project/bcm63xx/atf.git] / plat / rpi / rpi4 / rpi4_bl31_setup.c
index de582b3249cb1853c0ae1dadfca52478afbd86c2..58025b27a688c965139700aff18d36b09d53ecc8 100644 (file)
 #include <lib/mmio.h>
 #include <lib/xlat_tables/xlat_mmu_helpers.h>
 #include <lib/xlat_tables/xlat_tables_defs.h>
+#include <lib/xlat_tables/xlat_tables_v2.h>
 #include <plat/common/platform.h>
 
 #include <drivers/arm/gicv2.h>
 
 #include <rpi_shared.h>
 
+/*
+ * Fields at the beginning of armstub8.bin.
+ * While building the BL31 image, we put the stub magic into the binary.
+ * The GPU firmware detects this at boot time, clears that field as a
+ * confirmation and puts the kernel and DT address in the following words.
+ */
+extern uint32_t stub_magic;
+
 static const gicv2_driver_data_t rpi4_gic_data = {
        .gicd_base = RPI4_GIC_GICD_BASE,
        .gicc_base = RPI4_GIC_GICC_BASE,
@@ -141,6 +150,14 @@ void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
 
 void bl31_plat_arch_setup(void)
 {
+       /*
+        * Add the first page of memory, which holds the stub magic,
+        * the kernel and the DT address.
+        * This is read-only, as the GPU already populated the header,
+        * we just need to read it.
+        */
+       mmap_add_region(0, 0, 4096, MT_MEMORY | MT_RO | MT_SECURE);
+
        rpi3_setup_page_tables(BL31_BASE, BL31_END - BL31_BASE,
                               BL_CODE_BASE, BL_CODE_END,
                               BL_RO_DATA_BASE, BL_RO_DATA_END