Skip to content

Commit d04ff1a

Browse files
YuguoWHcarlescufi
authored andcommitted
arch: arc: Restore MPU registers to its initial states between tests
EMSK boards can't be reset between tests due to hardware configures. MPU v3 configs in previous test could cause exceptions in the following tests. This commit fixes this issue by restoring MPU registers initial states at early init stage. Signed-off-by: Yuguo Zou <[email protected]>
1 parent df4b780 commit d04ff1a

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

arch/arc/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,10 @@ config ARC_EXCEPTION_DEBUG
328328
and parameters, at a cost of code/data size for the human-readable
329329
strings.
330330

331+
config ARC_CUSTOM_INIT
332+
bool "Enable custom initialization code"
333+
help
334+
This option enables custom initialization code as a supplement
335+
method of initialization to some corner cases on SoCs and boards.
336+
331337
endmenu

arch/arc/core/reset.S

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,38 @@ invalidate_dcache:
121121

122122
done_cache_invalidate:
123123

124+
/*
125+
* ARC Custom Initialization
126+
* For scenarios where board hardware is not re-initialized between tests,
127+
* some settings need to be restored to its default initial states as a
128+
* substitution of normal hardware reset sequence.
129+
*/
130+
#if defined(CONFIG_ARC_CUSTOM_INIT)
131+
/* Set MPU (v3) registers to default */
132+
#if CONFIG_ARC_MPU_VER == 3
133+
/* Set default reset value to _ARC_V2_MPU_EN register */
134+
#define ARC_MPU_EN_RESET_VALUE 0x400181C0
135+
mov_s r1, ARC_MPU_EN_RESET_VALUE
136+
sr r1, [_ARC_V2_MPU_EN]
137+
/* Get MPU region numbers */
138+
lr r3, [_ARC_V2_MPU_BUILD]
139+
lsr_s r3, r3, 8
140+
and r3, r3, 0xff
141+
mov_s r1, 0
142+
mov_s r2, 0
143+
/* Set all MPU regions by iterating index */
144+
mpu_regions_reset:
145+
brge r2, r3, done_mpu_regions_reset
146+
sr r2, [_ARC_V2_MPU_INDEX]
147+
sr r1, [_ARC_V2_MPU_RSTART]
148+
sr r1, [_ARC_V2_MPU_REND]
149+
sr r1, [_ARC_V2_MPU_RPER]
150+
add_s r2, r2, 1
151+
b_s mpu_regions_reset
152+
done_mpu_regions_reset:
153+
#endif
154+
#endif
155+
124156
#if defined(CONFIG_SYS_POWER_DEEP_SLEEP_STATES) && \
125157
!defined(CONFIG_BOOTLOADER_CONTEXT_RESTORE)
126158
jl @_sys_resume_from_deep_sleep

boards/arc/em_starterkit/em_starterkit_em7d_defconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ CONFIG_GPIO=y
2020
CONFIG_ARC_MPU_ENABLE=y
2121
CONFIG_ARC_HAS_SECURE=y
2222
CONFIG_TRUSTED_EXECUTION_SECURE=y
23+
CONFIG_ARC_CUSTOM_INIT=y

0 commit comments

Comments
 (0)