Skip to content

Ability to relocate noinit section variables  #49155

Open
@pdgendt

Description

@pdgendt

Is your enhancement proposal related to a problem? Please describe.
It's currently not possible to relocate a zephyr heap (located in noinit section).
Additionally, the __noinit and __noinit_named macros extend to a section containing __FILE__ (for gcc) which contains characters that are incompatible for the linker.cmd to work.

Describe the solution you'd like
Adding an additional target to the cmake zephyr_code_relocate extension for the noinit section.

Describe alternatives you've considered
I've submitted a proposal here, however this affects the build mechanism greatly, and doesn't work for generator expressions.

Additional context
A simple example to demonstrate relocating a heap to DTCM, which currently doesn't build/work.

# CMakeLists.txt
cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(relocate)

# relocating everything to DTCM would also relocate instructions
zephyr_code_relocate(src/main.c DTCM_NOINIT)

target_sources(app PRIVATE src/main.c)
/* src/main.c */
#include <zephyr/kernel.h>

K_HEAP_DEFINE(custom_heap, 1024);

void main(void)
{
	void *ptr = k_heap_alloc(&custom_heap, 64, K_FOREVER);
	k_heap_free(&custom_heap, ptr);
}
# prj.conf
CONFIG_CODE_DATA_RELOCATION=y

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions