From 4ffa4bb861612f9debffc9088bac72a1ac611ff5 Mon Sep 17 00:00:00 2001 From: Yilun Lin Date: Wed, 20 Mar 2019 17:26:49 +0800 Subject: kukui_scp: Enable MPU to protect code RAM and data RAM in RW image. kukui_scp is loaded into SRAM. We would like to protect the memory from a modified code RAM content and executing injected code in data RAM. BRANCH=None BUG=b:123269246 TEST=Apply MPU test patch https://crrev.com/c/1530265. Test data ram XN: 1. mpu 0 # disable MPU 2. mpu_test # see it prints 3. mpu 1 # enable MPU 4. mpu_test # memory access violation, and reset. 5. mpu_test # memory access violation, and reset # again. (MPU enabled by default) Test code ram RO: 1. rw 0x8 0x5566 # Write to code RAM and see memory # access violation and reset. 2. mpu 0 # disable MPU 3. rw 0x8 0x5566 # Nothing happended 4. rw 0x8 # Read 0x5566 5. mpu 1 # enable MPU 6. rw 0x8 0x5566 # memory access violation. Change-Id: I6af5029d8c55d795543d4759b2c9168a06eb9ff1 Signed-off-by: Yilun Lin Reviewed-on: https://chromium-review.googlesource.com/1530264 Commit-Ready: Yilun Lin Tested-by: Yilun Lin Reviewed-by: Rong Chang --- include/config.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/config.h b/include/config.h index 22fbe4c6f7..171938d9cc 100644 --- a/include/config.h +++ b/include/config.h @@ -2773,10 +2773,19 @@ * Usually, CONFIG_DATA_RAM_SIZE = CONFIG_RAM_SIZE but some chips need to * allocate RAM for the mask ROM. Then CONFIG_DATA_RAM_SIZE > CONFIG_RAM_SIZE. * + * CONFIG_CODE_RAM_SIZE indicates the size of all code RAM available on the chip + * in bytes. This is needed when a chip with external storage where stored with + * code section, or a chip without an internal flash but need to protect its + * code section by MPU. + * Usually, CONFIG_CODE_RAM_SIZE = CONFIG_RO_SIZE. However, some chips may + * have other value, e.g. mt_scp which doesn't have RO image, and the code RAM + * size is actually its CONFIG_ROM_SIZE plus a reserved memory space. + * * CONFIG_ROM_SIZE indicates the size of ROM allocated by a linker script. This * is only needed when no physical flash present (!CONFIG_FLASH_PHYSICAL). The * ROM region will place common RO setions, e.g. .text, .rodata, .data LMA etc. */ +#undef CONFIG_CODE_RAM_SIZE #undef CONFIG_DATA_RAM_SIZE #undef CONFIG_RAM_SIZE #undef CONFIG_ROM_SIZE @@ -4007,12 +4016,20 @@ #error Must select one type of host communication bus. #endif +/******************************************************************************/ +/* + * Set default code ram size unless it's customized by the chip. + */ +#ifndef CONFIG_CODE_RAM_SIZE +#define CONFIG_CODE_RAM_SIZE CONFIG_RO_SIZE +#endif + /******************************************************************************/ /* * Set default data ram size unless it's customized by the chip. */ #ifndef CONFIG_DATA_RAM_SIZE -#define CONFIG_DATA_RAM_SIZE CONFIG_RAM_SIZE +#define CONFIG_DATA_RAM_SIZE CONFIG_RAM_SIZE #endif /******************************************************************************/ -- cgit v1.2.1