mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-27 06:50:21 +00:00
917410a0a8
* fbt: reworking targets & assets handling WIP * fbt: dist fixes * fbt: moved SD card resources to owning apps * unit_tests: moved resources to app folder * github: updated unit_tests paths * github: packaging fixes * unit_tests: fixes * fbt: assets: internal cleanup * fbt: reworked assets handling * github: unit_tests: reintroducing fixes * minor cleanup * fbt: naming changes to reflect private nature of scons tools * fbt: resources: fixed dist archive paths * docs: updated paths * docs: updated more paths * docs: included "resources" parameter in app manifest docs; updated assets readme * updated gitignore for assets * github: updated action versions * unit_tests: restored timeout; scripts: assets: logging changes * gh: don't upload desktop animations for unit test run Co-authored-by: あく <alleteam@gmail.com>
66 lines
No EOL
2 KiB
C
66 lines
No EOL
2 KiB
C
#include <furi_hal_mpu.h>
|
|
#include <stm32wbxx_ll_cortex.h>
|
|
|
|
#define FURI_HAL_MPU_ATTRIBUTES \
|
|
(LL_MPU_ACCESS_BUFFERABLE | LL_MPU_ACCESS_CACHEABLE | LL_MPU_ACCESS_SHAREABLE | \
|
|
LL_MPU_TEX_LEVEL1 | LL_MPU_INSTRUCTION_ACCESS_ENABLE)
|
|
|
|
#define FURI_HAL_MPU_STACK_PROTECT_REGION FuriHalMPURegionSize32B
|
|
|
|
void furi_hal_mpu_init() {
|
|
furi_hal_mpu_enable();
|
|
|
|
// NULL pointer dereference protection
|
|
furi_hal_mpu_protect_no_access(FuriHalMpuRegionNULL, 0x00, FuriHalMPURegionSize1MB);
|
|
}
|
|
|
|
void furi_hal_mpu_enable() {
|
|
LL_MPU_Enable(LL_MPU_CTRL_PRIVILEGED_DEFAULT);
|
|
}
|
|
|
|
void furi_hal_mpu_disable() {
|
|
LL_MPU_Disable();
|
|
}
|
|
|
|
void furi_hal_mpu_protect_no_access(
|
|
FuriHalMpuRegion region,
|
|
uint32_t address,
|
|
FuriHalMPURegionSize size) {
|
|
uint32_t size_ll = size;
|
|
size_ll = size_ll << MPU_RASR_SIZE_Pos;
|
|
|
|
furi_hal_mpu_disable();
|
|
LL_MPU_ConfigRegion(
|
|
region, 0x00, address, FURI_HAL_MPU_ATTRIBUTES | LL_MPU_REGION_NO_ACCESS | size_ll);
|
|
furi_hal_mpu_enable();
|
|
}
|
|
|
|
void furi_hal_mpu_protect_read_only(
|
|
FuriHalMpuRegion region,
|
|
uint32_t address,
|
|
FuriHalMPURegionSize size) {
|
|
uint32_t size_ll = size;
|
|
size_ll = size_ll << MPU_RASR_SIZE_Pos;
|
|
|
|
furi_hal_mpu_disable();
|
|
LL_MPU_ConfigRegion(
|
|
region, 0x00, address, FURI_HAL_MPU_ATTRIBUTES | LL_MPU_REGION_PRIV_RO_URO | size_ll);
|
|
furi_hal_mpu_enable();
|
|
}
|
|
|
|
void furi_hal_mpu_protect_disable(FuriHalMpuRegion region) {
|
|
furi_hal_mpu_disable();
|
|
LL_MPU_DisableRegion(region);
|
|
furi_hal_mpu_enable();
|
|
}
|
|
|
|
void furi_hal_mpu_set_stack_protection(uint32_t* stack) {
|
|
// Protection area address must be aligned to region size
|
|
uint32_t stack_ptr = (uint32_t)stack;
|
|
uint32_t mask = ((1 << (FURI_HAL_MPU_STACK_PROTECT_REGION + 2)) - 1);
|
|
stack_ptr &= ~mask;
|
|
if(stack_ptr < (uint32_t)stack) stack_ptr += (mask + 1);
|
|
|
|
furi_hal_mpu_protect_read_only(
|
|
FuriHalMpuRegionStack, stack_ptr, FURI_HAL_MPU_STACK_PROTECT_REGION);
|
|
} |