zephyr/samples
Carlo Caione d3203dc70d code_relocation: Add NOCOPY feature
* Use case of interest:

Some platforms are shipping in parallel to the internal FLASH some other
storage / external FLASH (usually a QSPI FLASH) that can be used to
execute (XIP) code from.

The content of this external FLASH can usually be written at flash time
using proper tools (see for example the case of the external FLASH on
the nRF5340DK that can be written at flash time using nrfjprog).

The external FLASH is a nice addition that is extremely useful when a
large application code doesn't entirely fit on the internal FLASH so
that we could want to move part of it in the auxiliary FLASH to XIP the
code from there.

* The problem:

Right now Zephyr doesn't have a formal and generic way to move at build
time part of the code to a different memory region.

* The current status:

Zephyr is indeed shipping a code_relocation feature but that doesn't
entirely match our needs.

When XIP is enabled, the code_relocation feature is used in Zephyr to
move the selected code (that is to copy text section, to initialize data
and zero bss) from FLASH to SRAM at run time and execute code from SRAM.

The relocation is done by a generated snippet of code that is
memcpy()-ing the right content to the destination region also using some
build-time generated portions of linker script to retrieve start and
destination addresses and regions.

* This patch:

This patch is leveraging the code_relocation code and adding a NOCOPY
feature. This feature is using the code_relocation feature to
dynamically build the linker script snippets but entirely skipping the
run-time code relocation so that the code can be XIP-ed from the
destination region.

* Example:

Let's say that we have a big file called `huge_file.c` that we want to
XIP from the external FLASH that is mapped in an EXTFLASH region.

In this case we should enable `CONFIG_XIP` and
`CONFIG_CODE_DATA_RELOCATION` and instruct cmake as follows:

  zephyr_code_relocate(src/huge_file.c EXTFLASH_TEXT NOCOPY)
  zephyr_code_relocate(src/huge_file.c SRAM_DATA)

this means that:

- The .text section of the `huge_file.c` must reside in the EXTFLASH
  memory region and we do not need to copy the section there because we
  are going to XIP it (and we assume that the file is going to be placed
  in the external FLASH at flash time).
- The .data section of the `huge_file.c` must still reside in the SRAM
  memory region.

* TODOs:

It's desirable to have the possibility to relocate libraries and
pre-build files instead of source code files.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
2022-02-21 22:09:46 -05:00
..
application_development code_relocation: Add NOCOPY feature 2022-02-21 22:09:46 -05:00
arch lib: os: crc: Rework the crc16() implementation 2022-02-04 12:33:22 -05:00
basic samples: blinky_pwm: decreased min PWM period for blinky sample 2022-02-10 14:33:08 -05:00
bluetooth Bluetooth: Add common BT_CONN_INTERVAL_TO_MS macro 2022-02-21 19:40:42 -05:00
boards pm: Reference pm_state_info only by pointer 2022-02-21 20:58:01 -05:00
compression samples/compression/l4z: Increase min_ram 2022-01-28 10:07:00 +01:00
drivers samples: drivers: can: add CONFIG_GPIO to prj 2022-02-15 13:06:27 -05:00
hello_world
kernel samples: fix the metairq_dispatch sample failed on acrn_ehl_crb 2022-02-10 08:55:39 -05:00
modules samples: modules: canopennode: Fix example code 2022-01-28 10:05:58 +01:00
net samples: rename user-tls.conf to user-tls-conf.h 2022-02-21 20:55:20 -05:00
philosophers samples: fix wrong extra_args definitions 2022-01-04 17:15:06 -05:00
posix
sensor sensors: STM32: Add support for L5 die temp sensor 2022-01-13 10:34:10 +01:00
shields
subsys doc: add OTA section to device management 2022-02-21 20:39:08 -05:00
synchronization
tfm_integration samples: rename user-tls.conf to user-tls-conf.h 2022-02-21 20:55:20 -05:00
userspace boards/intel_adsp_cavs25: Improve test coverage 2022-01-21 14:36:49 -05:00
classic.rst
index.rst