aboutsummaryrefslogtreecommitdiff
path: root/module/msys_rom
diff options
context:
space:
mode:
authorChris Kay <chris.kay@arm.com>2019-12-20 19:23:15 +0000
committerjimqui01 <54316584+jimqui01@users.noreply.github.com>2020-03-11 11:14:37 +0000
commit5e0088d91e69712bcbeef056a538ca9a3e79e136 (patch)
tree2ea39b6a5d5224e2ca7fe9e9a56eb2e110443148 /module/msys_rom
parent5e4f8b0865462f9dfa5cecdd8b4bb409940d2a1e (diff)
bootloader: Don't access R/W memory when bootloading
The RAM firmware image is loaded from the beginning of SRAM, which overlaps read/write data used by the ROM firmware. This has the potential to corrupt ROM runtime data that is still being loaded in and out of memory while it is preparing to boot the image. This patch removes the image booting logic from the `msys_rom` and `juno_rom` modules and moves it to the `bootloader` module to ensure that the transfer is properly and safely contained and controlled. Other changes to reduce exploitability including updating the stack pointer to the one expected by the RAM firmware rather than permitting it to continue from where the ROM firmware left off, and relocating the vector table to the one embedded in the RAM firmware image, which prevents the core from using the exception handlers created during ROM boot (which are in the heap and may have been corrupted while loading the RAM firmware). Change-Id: I4413c1cd058ca93ef04177424f1f29561b10872f Signed-off-by: Chris Kay <chris.kay@arm.com>
Diffstat (limited to 'module/msys_rom')
-rw-r--r--module/msys_rom/include/mod_msys_rom.h7
-rw-r--r--module/msys_rom/src/mod_msys_rom.c59
2 files changed, 17 insertions, 49 deletions
diff --git a/module/msys_rom/include/mod_msys_rom.h b/module/msys_rom/include/mod_msys_rom.h
index 1506a2aa..ce682698 100644
--- a/module/msys_rom/include/mod_msys_rom.h
+++ b/module/msys_rom/include/mod_msys_rom.h
@@ -12,9 +12,11 @@
#ifndef MOD_MSYS_ROM_H
#define MOD_MSYS_ROM_H
+#include <fwk_id.h>
+#include <fwk_module_idx.h>
+
#include <stddef.h>
#include <stdint.h>
-#include <fwk_id.h>
/*!
* \ingroup GroupMSYSModule
@@ -32,9 +34,6 @@ struct msys_rom_config {
/*! Size of the AP context area */
const size_t ap_context_size;
- /*! Base address of the RAM firmware image */
- const uintptr_t ramfw_base;
-
/*! Element ID of the primary cluster PPU */
const fwk_id_t id_primary_cluster;
diff --git a/module/msys_rom/src/mod_msys_rom.c b/module/msys_rom/src/mod_msys_rom.c
index 5c6093cc..001bb4c2 100644
--- a/module/msys_rom/src/mod_msys_rom.c
+++ b/module/msys_rom/src/mod_msys_rom.c
@@ -9,22 +9,21 @@
* firmware.
*/
-#include <stdbool.h>
-#include <stdint.h>
-#include <string.h>
+#include <mod_bootloader.h>
+#include <mod_log.h>
+#include <mod_msys_rom.h>
+#include <mod_power_domain.h>
+#include <mod_ppu_v1.h>
+
#include <fwk_assert.h>
-#include <fwk_interrupt.h>
#include <fwk_module.h>
-#include <fwk_module_idx.h>
#include <fwk_noreturn.h>
#include <fwk_notification.h>
#include <fwk_status.h>
#include <fwk_thread.h>
-#include <mod_bootloader.h>
-#include <mod_log.h>
-#include <mod_msys_rom.h>
-#include <mod_power_domain.h>
-#include <mod_ppu_v1.h>
+
+#include <stdbool.h>
+#include <string.h>
struct msys_rom_ctx {
const struct msys_rom_config *rom_config;
@@ -39,34 +38,6 @@ enum rom_event {
ROM_EVENT_COUNT
};
-/*
- * This function assumes that the RAM firmware image is located at the beginning
- * of the SCP SRAM. The reset handler will be at offset 0x4.
- */
-static noreturn void msys_jump_to_ramfw(void)
-{
- uintptr_t const *reset_base =
- (uintptr_t *)(ctx.rom_config->ramfw_base + 0x4);
- void (*ramfw_reset_handler)(void);
-
- /*
- * Disable interrupts for the duration of the ROM firmware to RAM firmware
- * transition.
- */
- fwk_interrupt_global_disable();
-
- ramfw_reset_handler = (void (*)(void))*reset_base;
-
- /*
- * Execute the RAM firmware's reset handler to pass control from ROM
- * firmware to the RAM firmware.
- */
- ramfw_reset_handler();
-
- while (true)
- continue;
-}
-
static int msys_deferred_setup(void)
{
int status;
@@ -83,15 +54,13 @@ static int msys_deferred_setup(void)
ctx.log_api->log(MOD_LOG_GROUP_INFO, "[SYSTEM] Primary CPU powered\n");
status = ctx.bootloader_api->load_image();
- if (status != FWK_SUCCESS) {
- ctx.log_api->log(MOD_LOG_GROUP_ERROR,
- "[SYSTEM] Failed to load RAM firmware image\n");
- return FWK_E_DATA;
- }
- msys_jump_to_ramfw();
+ ctx.log_api->log(
+ MOD_LOG_GROUP_ERROR,
+ "[SYSTEM] Failed to load RAM firmware image: %d\n",
+ status);
- return FWK_SUCCESS;
+ return FWK_E_DATA;
}
/*