Skip to content

arch: arm: cortex_a_r: Fix linker script #77291

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 1 commit into from
Mar 31, 2025

Conversation

mausys
Copy link

@mausys mausys commented Aug 20, 2024

This commit fixes overlapping MMU regions. If ROM_ADDR equals RAM_ADDR, the current output location counter will not be resetted, so the _image_ram range doesn't include the __text_region range.

Copy link

Hello @mausys, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

Copy link
Collaborator

@ithinuel ithinuel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. I think it would be valuable to try to keep this file aligned with its aarch64 variant.

@carlocaione I see this is not conditioned in aarch64 either.
Do you have any recommendation on this matter ?

@carlocaione
Copy link
Collaborator

@mausys please fix the CI errors. Also, can you give a reproducer for the problem you are seeing?

@mausys mausys force-pushed the fix_arm_linker_script branch from 05dad1c to 47f3315 Compare August 22, 2024 10:43
@mausys
Copy link
Author

mausys commented Aug 22, 2024

You can check the generated .map file for a non-XIP project (my target is a zynq 7000). The value of the variable _image_ram_start is less than that of _text_region_start, while _image_ram_end is greater than __text_region_end. That means, that _image_ram includes the __text_region. All those variables are used in arm_mmu.c to create the page table entries. I'm not sure what happens when multiple page table entries exist for a page. But the code segment might become writable, what could be a security issue. Anyway it creates unnecessary page table entries.

@mausys
Copy link
Author

mausys commented Aug 22, 2024

I analyzed the arm_mmu.c again and as far as I understand, maybe no duplicate entries are created and instead the code segment overwrites the wrong data segment entries. But this is confusing.

@mausys mausys force-pushed the fix_arm_linker_script branch from 47f3315 to 2126d8b Compare August 30, 2024 08:24
@ithinuel
Copy link
Collaborator

@carlocaione Does @mausys’s replies answer your question?

@kartben
Copy link
Collaborator

kartben commented Nov 25, 2024

@carlocaione Does @mausys’s replies answer your question?

@carlocaione ping? :)

@ithinuel ithinuel assigned wearyzen and unassigned ithinuel Jan 17, 2025
@mausys mausys force-pushed the fix_arm_linker_script branch from fbdcbac to 3332bff Compare February 11, 2025 15:04
Copy link
Collaborator

@wearyzen wearyzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding "fix" in commit title helps identify fixes and instead of "like e102e37690a" could you add some more comments?
Here is a rough draft of what I think could be added instead for both commits:

arch: arm: cortex_m: fix text region overlap with ram in !XIP

ROM_ADDR and RAM_ADDR is same when CONFIG_XIP is not defined.
If we reset the location for RAMABLE region to RAM_ADDR text region,
which is part of rom, overlaps with initial ram region.
This commit tries to avoid this incorrect behaviour for cortex_m

@mausys mausys force-pushed the fix_arm_linker_script branch from 3332bff to cc2972b Compare February 14, 2025 10:25
@kartben kartben requested review from ithinuel and wearyzen February 14, 2025 10:41
@kartben
Copy link
Collaborator

kartben commented Feb 14, 2025

@ithinuel has your request for change been addressed properly? If yes, please revisit your -1, thanks!

@wearyzen
Copy link
Collaborator

@mausys, sorry for the oversight, could you please remove my name from the commit message as a co-author? I don't think adding review comments always counts for co-authorship. Appreciate your help!

@kartben kartben added this to the v4.1.0 milestone Feb 15, 2025
ROM_ADDR and RAM_ADDR is same when CONFIG_XIP is not defined.
If we reset the location for RAMABLE region to RAM_ADDR text region,
which is part of rom, overlaps with initial ram region.
This commit tries to avoid this incorrect behaviour for cortex_a
and cortex_m

Signed-off-by: Simon Maurer <mail@maurer.systems>
@mausys mausys force-pushed the fix_arm_linker_script branch from cc2972b to 8ac1faf Compare February 18, 2025 17:37
@fabiobaltieri fabiobaltieri removed this from the v4.1.0 milestone Mar 7, 2025
@kartben kartben merged commit d5d4d57 into zephyrproject-rtos:main Mar 31, 2025
21 checks passed
@kartben
Copy link
Collaborator

kartben commented Apr 1, 2025

Hi @mausys @ithinuel @wearyzen
This seems to be causing a CI failure in main (https://github.com/zephyrproject-rtos/zephyr/actions/runs/14185617769/job/39740279567) -- could you please look into it?

west twister -p qemu_cortex_a9/xc7z007s -s cpp.libcxx.glibcxx.picolibc --no-detailed-test-id


ERROR   - *** Booting Zephyr OS build v4.1.0-1600-g2eb8cfb7f508 ***
Running TESTSUITE libcxx_tests
===================================================================
version 201703
START - test_array
 PASS - test_array in 0.001 seconds
===================================================================
START - test_exception
E: ***** DATA ABORT *****
E: Unknown (7)
E: r0/a1:  0x0010c264  r1/a2:  0x00000047  r2/a3:  0x0010ada5
E: r3/a4:  0x00000048 r12/ip:  0x001bb9b0 r14/lr:  0x00101285
E:  xpsr:  0x2000013f
E: Faulting instruction address (r15/pc): 0x00101248
E: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0
E: Current thread: 0x128000 (test_exception)
E: Halting system



@wearyzen
Copy link
Collaborator

wearyzen commented Apr 1, 2025

@kartben , #87965 should fix the ci

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Architectures area: ARM ARM (32-bit) Architecture
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants