-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Setup MPU for memory regions defined into the DT #43119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| cmake_minimum_required(VERSION 3.20.0) | ||
|
|
||
| find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) | ||
| project(arm_mpu_regions) | ||
|
|
||
| target_sources(app PRIVATE src/main.c) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Copyright (c) 2021 Carlo Caione <[email protected]> | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| / { | ||
| /delete-node/ memory@20000000; | ||
|
|
||
| sram0: memory@20000000 { | ||
| compatible = "mmio-sram"; | ||
| reg = <0x20000000 0x200000>; | ||
| }; | ||
|
|
||
| sram_cache: memory@20200000 { | ||
| compatible = "zephyr,memory-region", "mmio-sram"; | ||
| reg = <0x20200000 0x100000>; | ||
| zephyr,memory-region = "SRAM_CACHE"; | ||
| zephyr,memory-region-mpu = "RAM"; | ||
| }; | ||
|
|
||
| sram_no_cache: memory@20300000 { | ||
| compatible = "zephyr,memory-region", "mmio-sram"; | ||
| reg = <0x20300000 0x100000>; | ||
| zephyr,memory-region = "SRAM_NO_CACHE"; | ||
| zephyr,memory-region-mpu = "RAM_NOCACHE"; | ||
| }; | ||
|
|
||
| sram_dtcm_fake: memory@abcdabcd { | ||
| compatible = "zephyr,memory-region", "arm,dtcm"; | ||
| reg = <0xabcdabcd 0x100000>; | ||
| zephyr,memory-region = "SRAM_DTCM_FAKE"; | ||
| zephyr,memory-region-mpu = "RAM"; | ||
| }; | ||
|
|
||
| sram_no_mpu: memory@deaddead { | ||
| compatible = "zephyr,memory-region", "mmio-sram"; | ||
| reg = <0xdeaddead 0x100000>; | ||
| zephyr,memory-region = "SRAM_NO_MPU"; | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| CONFIG_ZTEST=y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright (c) 2021 Carlo Caione <[email protected]> | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <zephyr.h> | ||
| #include <linker/linker-defs.h> | ||
| #include <sys/slist.h> | ||
| #include <arch/arm/aarch32/mpu/arm_mpu.h> | ||
| #include <ztest.h> | ||
| #include <string.h> | ||
|
|
||
| extern const struct arm_mpu_config mpu_config; | ||
|
|
||
| static arm_mpu_region_attr_t cacheable = REGION_RAM_ATTR(REGION_1M); | ||
| static arm_mpu_region_attr_t noncacheable = REGION_RAM_NOCACHE_ATTR(REGION_1M); | ||
|
|
||
| static void test_regions(void) | ||
| { | ||
| int cnt = 0; | ||
|
|
||
| for (size_t i = 0; i < mpu_config.num_regions; i++) { | ||
| const struct arm_mpu_region *r = &mpu_config.mpu_regions[i]; | ||
|
|
||
| if (!strcmp(r->name, "SRAM_CACHE")) { | ||
| zassert_equal(r->base, 0x20200000, "Wrong base"); | ||
| zassert_equal(r->attr.rasr, cacheable.rasr, | ||
| "Wrong attr for SRAM_CACHE"); | ||
| cnt++; | ||
| } else if (!strcmp(r->name, "SRAM_NO_CACHE")) { | ||
| zassert_equal(r->base, 0x20300000, "Wrong base"); | ||
| zassert_equal(r->attr.rasr, noncacheable.rasr, | ||
| "Wrong attr for SRAM_NO_CACHE"); | ||
| cnt++; | ||
| } else if (!strcmp(r->name, "SRAM_DTCM_FAKE")) { | ||
| zassert_equal(r->base, 0xabcdabcd, "Wrong base"); | ||
| zassert_equal(r->attr.rasr, cacheable.rasr, | ||
| "Wrong attr for SRAM_DTCM_FAKE"); | ||
| cnt++; | ||
| } | ||
| } | ||
|
|
||
| if (cnt != 3) { | ||
| /* | ||
| * SRAM0 and SRAM_NO_MPU should not create any MPU region. | ||
| * Check that. | ||
| */ | ||
| ztest_test_fail(); | ||
| } | ||
| } | ||
|
|
||
| void test_main(void) | ||
| { | ||
| ztest_test_suite(test_c_arm_mpu_regions, | ||
| ztest_unit_test(test_regions) | ||
| ); | ||
|
|
||
| ztest_run_test_suite(test_c_arm_mpu_regions); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| tests: | ||
| misc.arm_mpu_regions: | ||
| platform_allow: mps2_an385 | ||
| tags: sample board sram mpu |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.