forked from arduino/ArduinoCore-zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixups.c
147 lines (123 loc) · 3.65 KB
/
fixups.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <cmsis_core.h>
#include <zephyr/init.h>
int disable_mpu_rasr_xn(void)
{
uint32_t index;
/* Kept the max index as 8(irrespective of soc) because the sram
* would most likely be set at index 2.
*/
for (index = 0U; index < 8; index++) {
MPU->RNR = index;
#if defined(CONFIG_ARMV8_M_BASELINE) || defined(CONFIG_ARMV8_M_MAINLINE)
if (MPU->RBAR & MPU_RBAR_XN_Msk) {
MPU->RBAR ^= MPU_RBAR_XN_Msk;
}
#else
if (MPU->RASR & MPU_RASR_XN_Msk) {
MPU->RASR ^= MPU_RASR_XN_Msk;
}
#endif /* CONFIG_ARMV8_M_BASELINE || CONFIG_ARMV8_M_MAINLINE */
}
return 0;
}
#if defined(CONFIG_BOARD_ARDUINO_NANO_33_BLE)
int disable_bootloader_mpu() {
// MPU was previously enabled in the bootloader
// https://github.com/bcmi-labs/zephyr/blob/31cb7dd00fd5bce4c69896b3b2ddf6259d0c0f2b/boards/arm/arduino_nano_33_ble/arduino_nano_33_ble_defconfig#L10C1-L10C15
__disable_irq();
disable_mpu_rasr_xn();
__DMB();
MPU->CTRL = 0;
__enable_irq();
return 0;
}
SYS_INIT(disable_bootloader_mpu, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
#endif
#if defined(CONFIG_ARM_MPU)
SYS_INIT(disable_mpu_rasr_xn, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT);
#endif
#if defined(CONFIG_BOARD_ARDUINO_GIGA_R1) && defined(CONFIG_VIDEO)
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/drivers/clock_control.h>
#include <zephyr/logging/log.h>
int camera_ext_clock_enable(void)
{
int ret;
uint32_t rate;
const struct device *cam_ext_clk_dev = DEVICE_DT_GET(DT_NODELABEL(pwmclock));
if (!device_is_ready(cam_ext_clk_dev)) {
return -ENODEV;
}
ret = clock_control_on(cam_ext_clk_dev, (clock_control_subsys_t)0);
if (ret < 0) {
return ret;
}
ret = clock_control_get_rate(cam_ext_clk_dev, (clock_control_subsys_t)0, &rate);
if (ret < 0) {
return ret;
}
return 0;
}
SYS_INIT(camera_ext_clock_enable, POST_KERNEL, CONFIG_CLOCK_CONTROL_PWM_INIT_PRIORITY);
#endif
#if defined(CONFIG_SHARED_MULTI_HEAP)
#include <zephyr/kernel.h>
#include <zephyr/devicetree.h>
#include <zephyr/multi_heap/shared_multi_heap.h>
__stm32_sdram1_section static uint8_t __aligned(32) smh_pool[4*1024*1024];
int smh_init(void) {
int ret = 0;
ret = shared_multi_heap_pool_init();
if (ret != 0) {
return ret;
}
struct shared_multi_heap_region smh_sdram = {
.addr = (uintptr_t) smh_pool,
.size = sizeof(smh_pool),
.attr = SMH_REG_ATTR_EXTERNAL,
};
ret = shared_multi_heap_add(&smh_sdram, NULL);
if (ret != 0) {
return ret;
}
return 0;
}
SYS_INIT(smh_init, POST_KERNEL, CONFIG_CLOCK_CONTROL_PWM_INIT_PRIORITY);
#endif
#if defined(CONFIG_BOARD_ARDUINO_PORTENTA_C33) && defined(CONFIG_LLEXT)
#include <zephyr/kernel.h>
#include <zephyr/storage/flash_map.h>
int maybe_flash_bootloader(void)
{
// memcmp the first 256bytes of "embedded bootloader" and address 0x0
// if they are different, flash the bootloader
const uint8_t embedded_bootloader[] = {
#include "c33_bl_patch/c33_bl.bin.inc"
};
const struct flash_area *fa;
int rc;
rc = flash_area_open(FIXED_PARTITION_ID(mcuboot), &fa);
if (rc) {
printk("Failed to open flash area, rc %d\n", rc);
return rc;
}
uint8_t flash_bootloader[256];
flash_area_read(fa, 0, flash_bootloader, 256);
if (memcmp(embedded_bootloader, flash_bootloader, 256) != 0) {
// flash the bootloader
rc = flash_area_erase(fa, 0, fa->fa_size);
if (rc) {
printk("Failed to erase flash area, rc %d\n", rc);
return rc;
}
flash_area_write(fa, 0, embedded_bootloader, sizeof(embedded_bootloader));
if (rc) {
printk("Failed to write flash area, rc %d\n", rc);
return rc;
}
}
return 0;
}
SYS_INIT(maybe_flash_bootloader, POST_KERNEL, CONFIG_FILE_SYSTEM_INIT_PRIORITY);
#endif