-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Script to relocate code/data/bss sections to different memory types. #10892
Merged
nashif
merged 14 commits into
zephyrproject-rtos:master
from
varun-sha:linker_relocate_script
Dec 7, 2018
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8907960
scripts: gen_relocate_app.py: Script for relocating files in memory.
AdithyaBaglody be46803
cmake: Added rule and helper functions for code relocation.
AdithyaBaglody 73fb55a
kernel: init.c: Added required hooks for the relocation
AdithyaBaglody a8626f4
arch: Kconfig: Increased the text area for kobject and priv stack
AdithyaBaglody 229b96b
samples: code_relocation: An example for code relocation feature.
AdithyaBaglody aa00b35
doc: code_data_relocation: Details about code data relocation feature
varun-sha c3c69fe
tests: benchmarks: timing_info: Remove common variables
AdithyaBaglody 6890855
drivers: ipm: ipm_quark_se: Remove object declaration from header
AdithyaBaglody 046f387
include: drivers: pci: pci_mgr.h: Create a typdef instead of obj.
AdithyaBaglody 03ca77f
include: stats.h: Packed attribute was incorrect.
AdithyaBaglody ba73813
soc: ti_simplelink: cc32xx: soc.h: Incorrect enum definition.
AdithyaBaglody 15501a3
tests: subsys: fs: Fixed headers which were creating objects.
AdithyaBaglody fd8f82b
samples: rpl_border_router: Fixed headers files.
AdithyaBaglody ff312b3
CMakeLists.txt: Enable -fno-common globally.
AdithyaBaglody 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -15,3 +15,4 @@ Developer Guides | |
../README.rst | ||
../west/index.rst | ||
coccinelle.rst | ||
relocation.rst |
This file contains 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,97 @@ | ||
.. _code_data_relocation: | ||
|
||
Code data relocation | ||
#################### | ||
|
||
Overview | ||
******** | ||
This script will relocate .text, .rodata, .data, and .bss sections from | ||
required files and place them in the required memory region. The | ||
memory region and file are given to this python script in the form | ||
of a string. This script is always invoked from inside cmake. | ||
|
||
This script provides a robust way to re-order | ||
the memory contents without actually having to modify the code. | ||
In simple terms this script will do the job of | ||
``__attribute__((section("name")))`` for a bunch of files together. | ||
|
||
Details | ||
******* | ||
The memory region and file are given to this python script in the form of a string. | ||
|
||
An example of such a string is: | ||
``SRAM2:/home/xyz/zephyr/samples/hello_world/src/main.c,SRAM1:/home/xyz/zephyr/samples/hello_world/src/main2.c`` | ||
|
||
This script is invoked with the following parameters: | ||
``python3 gen_relocate_app.py -i input_string -o generated_linker -c generated_code`` | ||
|
||
Kconfig :option:`CONFIG_CODE_DATA_RELOCATION` option, when enabled in ``prj.conf``, will | ||
invoke the script and do the required relocation. | ||
|
||
This script also trigger the generation of ``linker_relocate.ld`` and ``code_relocation.c`` files. | ||
The ``linker_relocate.ld`` file creates appropriate sections and | ||
links the required functions or variables from all the selected files. | ||
|
||
**Note**: | ||
The text section is split into 2 parts in the main linker script. The first section | ||
will have some info regarding vector tables and other debug related info. | ||
The second section will have the complete text section. | ||
This is needed to force the required functions and data variables to the correct locations. | ||
This is due to the behavior of the linker. The linker will only link once and | ||
hence this text section had to be split to make room for the generated linker script. | ||
|
||
The ``code_relocation.c`` file has code that is needed for | ||
initializing data sections, and a copy of the text sections (if XIP). | ||
Also this contains code needed for bss zeroing and | ||
for data copy operations from ROM to required memory type. | ||
|
||
**The procedure to invoke this feature is:** | ||
|
||
* Enable :option:`CONFIG_CODE_DATA_RELOCATION` in the ``prj.conf`` file | ||
|
||
* Inside the ``CMakeLists.txt`` file in the project, mention | ||
all the files that need relocation. | ||
|
||
``zephyr_code_relocate(src/*.c SRAM2)`` | ||
|
||
Where the first argument is the file/files and the second | ||
argument is the memory where it must be placed. | ||
|
||
.. note:: | ||
The file argument supports limited regular expressions. | ||
function zephyr_code_relocate() can be called as many times as required. | ||
This step has to be performed before the inclusion of boilerplate.cmake. | ||
|
||
|
||
Additional Configurations | ||
========================= | ||
This section shows additional configuration options that can be set in ``CMakeLists.txt`` | ||
|
||
* if the memory is SRAM1, SRAM2, CCD, or AON, then place the full object in the sections | ||
for example: | ||
|
||
.. code-block:: none | ||
|
||
zephyr_code_relocate(src/file1.c SRAM2) | ||
zephyr_code_relocate(src/file2.c.c SRAM) | ||
|
||
* if the memory type is appended with _DATA, _TEXT, _RODATA or _BSS, only the | ||
selected memory is placed in the required memory region. | ||
for example: | ||
|
||
.. code-block:: none | ||
|
||
zephyr_code_relocate(src/file1.c SRAM2_DATA) | ||
zephyr_code_relocate(src/file2.c.c SRAM2_TEXT) | ||
|
||
* Multiple regions can also be appended together such as: SRAM2_DATA_BSS. | ||
This will place data and bss inside SRAM2. | ||
|
||
Sample | ||
====== | ||
A sample showcasing this feature is provided at | ||
``$ZEPHYR_BASE/samples/test_relocation/`` | ||
|
||
This is an example of using the code relocation feature. | ||
This example will place .text, .data, .bss from 3 files to various parts in the SRAM | ||
using a custom linker file derived from ``include/arch/arm/cortex_m/scripts/linker.ld`` |
This file contains 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 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 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 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 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 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
18 changes: 18 additions & 0 deletions
18
samples/application_development/code_relocation/CMakeLists.txt
This file contains 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,18 @@ | ||
cmake_minimum_required(VERSION 3.8.2) | ||
|
||
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) | ||
project(test_relocation) | ||
|
||
FILE(GLOB app_sources src/*.c) | ||
target_sources(app PRIVATE ${app_sources}) | ||
|
||
# Code relocation feature | ||
zephyr_code_relocate(src/test_file1.c SRAM2) | ||
|
||
zephyr_code_relocate(src/test_file2.c SRAM) | ||
|
||
zephyr_code_relocate(src/test_file3.c SRAM2_TEXT) | ||
zephyr_code_relocate(src/test_file3.c SRAM_DATA) | ||
zephyr_code_relocate(src/test_file3.c SRAM2_BSS) | ||
|
||
zephyr_code_relocate(../../../kernel/sem.c SRAM) |
4 changes: 4 additions & 0 deletions
4
samples/application_development/code_relocation/custom-sections.ld
This file contains 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 @@ | ||
SECTION_DATA_PROLOGUE(_CUSTOM_SECTION_NAME2,,) | ||
{ | ||
KEEP(*(".custom_section.*")); | ||
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commit message needs to be re-written.
It should be clear to the reader that this is a
breaking change and how to identify whether he is affected.
The discussion leading up to this change had a good explanation
I believe.
This is so that, when this breaks something, it is easier to identify
where it broke.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SebastianBoe yep make it a bit more verbose. Please re-review.