Mbed OS Reference
Loading...
Searching...
No Matches
mpu_api.h
1
2/** \addtogroup hal */
3/** @{*/
4/* mbed Microcontroller Library
5 * Copyright (c) 2018-2018 ARM Limited
6 * SPDX-License-Identifier: Apache-2.0
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20#ifndef MBED_MPU_API_H
21#define MBED_MPU_API_H
22
23#include "device.h"
24#include <stdbool.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#if DEVICE_MPU
31
32/**
33 * \defgroup hal_mpu MPU hal
34 *
35 * The MPU hal provides a simple MPU API to enhance device security by preventing
36 * execution from ram.
37 *
38 * # Defined behavior
39 * * The function ::mbed_mpu_init is safe to call repeatedly - Verified by mpu_init_test
40 * * The function ::mbed_mpu_free disables MPU protection - Verified by mpu_free_test
41 * * Execution from RAM results in a fault when execute never is enabled.
42 * This RAM includes heap, stack, data and zero init - Verified by mpu_fault_test_data,
43 * mpu_fault_test_bss, mpu_fault_test_stack and mpu_fault_test_heap.
44 * * Writing to ROM results in a fault when write never is enabled - Not verified
45 *
46 * # Undefined behavior
47 * * Calling any function other than ::mbed_mpu_init before the initialization of the MPU.
48 *
49 * @see hal_mpu_tests
50 *
51 * @{
52 */
53
54/**
55 * \defgroup hal_mpu_tests MPU hal tests
56 * The MPU test validates proper implementation of the MPU hal.
57 *
58 * To run the MPU hal tests use the command:
59 *
60 * mbed test -t <toolchain> -m <target> -n tests-mbed_hal-mpu*
61 */
62
63
64/**
65 * Initialize the MPU
66 *
67 * Initialize or re-initialize the memory protection unit.
68 * After initialization or re-initialization, ROM and RAM protection
69 * are both enabled.
70 */
71void mbed_mpu_init(void);
72
73/**
74 * Enable or disable ROM MPU protection
75 *
76 * This function is used to mark all of ROM as read and execute only.
77 * When enabled writes to ROM cause a fault.
78 *
79 * By default writes to ROM are disabled.
80 *
81 * @param enable true to disable writes to ROM, false otherwise
82 */
83void mbed_mpu_enable_rom_wn(bool enable);
84
85/**
86 * Enable or disable ram MPU protection
87 *
88 * This function is used to mark all of RAM as execute never.
89 * When enabled code is only allowed to execute from flash.
90 *
91 * By default execution from RAM is disabled.
92 *
93 * @param enable true to disable execution from RAM, false otherwise
94 */
95void mbed_mpu_enable_ram_xn(bool enable);
96
97/** Deinitialize the MPU
98 *
99 * Powerdown the MPU in preparation for powerdown, reset or jumping to another application.
100 */
101void mbed_mpu_free(void);
102
103/**@}*/
104
105#else
106
107#define mbed_mpu_init()
108
109#define mbed_mpu_enable_rom_wn(enable) (void)enable
110
111#define mbed_mpu_enable_ram_xn(enable) (void)enable
112
113#define mbed_mpu_free()
114
115#endif
116
117#ifdef __cplusplus
118}
119#endif
120
121#endif
122
123/** @}*/
void mbed_mpu_enable_rom_wn(bool enable)
Enable or disable ROM MPU protection.
void mbed_mpu_init(void)
Initialize the MPU.
void mbed_mpu_free(void)
Deinitialize the MPU.
void mbed_mpu_enable_ram_xn(bool enable)
Enable or disable ram MPU protection.