Skip to content

Commit 9cb7b9e

Browse files
pdgendtdanieldegrasse
authored andcommitted
linker: Split nocache memory sections into loadable and non-loadable
Commit f9168ae made all non-cached memory loadable by default. However as nocache memory is typically used for reserving larger buffers to be shared between peripherals, this comes at fairly large cost towards ROM usage. This commit creates two distinct sections for both loadable and non-loadable nocache memory sections. Signed-off-by: Pieter De Gendt <[email protected]> (cherry picked from commit 294f7e5)
1 parent e395a9a commit 9cb7b9e

File tree

6 files changed

+46
-12
lines changed

6 files changed

+46
-12
lines changed

arch/common/nocache.ld

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
/*
22
* Copyright (c) 2019 Nordic Semiconductor ASA
33
* Copyright (c) 2019 Intel Corporation
4+
* Copyright (c) 2025 Basalte bv
45
*
56
* SPDX-License-Identifier: Apache-2.0
67
*/
78

89
/* Copied from linker.ld */
910

1011
/* Non-cached region of RAM */
11-
SECTION_DATA_PROLOGUE(_NOCACHE_SECTION_NAME,,)
12+
SECTION_DATA_PROLOGUE(_NOCACHE_SECTION_NAME,(NOLOAD),)
1213
{
1314
#if defined(CONFIG_MMU)
1415
MMU_ALIGN;
1516
#else
16-
MPU_ALIGN(_nocache_ram_size);
17+
MPU_ALIGN(_nocache_noload_ram_size);
1718
#endif
1819
_nocache_ram_start = .;
20+
_nocache_noload_ram_start = .;
1921
*(.nocache)
2022
*(".nocache.*")
2123

@@ -24,9 +26,32 @@ SECTION_DATA_PROLOGUE(_NOCACHE_SECTION_NAME,,)
2426
#if defined(CONFIG_MMU)
2527
MMU_ALIGN;
2628
#else
27-
MPU_ALIGN(_nocache_ram_size);
29+
MPU_ALIGN(_nocache_noload_ram_size);
2830
#endif
31+
_nocache_noload_ram_end = .;
32+
} GROUP_DATA_LINK_IN(RAMABLE_REGION, RAMABLE_REGION)
33+
_nocache_noload_ram_size = _nocache_noload_ram_end - _nocache_noload_ram_start;
34+
35+
/* Non-cached loadable region of RAM and ROM */
36+
SECTION_DATA_PROLOGUE(_NOCACHE_LOAD_SECTION_NAME,,)
37+
{
38+
#if defined(CONFIG_MMU)
39+
MMU_ALIGN;
40+
#else
41+
MPU_ALIGN(_nocache_load_ram_size);
42+
#endif
43+
_nocache_load_ram_start = .;
44+
*(.nocache_load)
45+
*(".nocache_load.*")
46+
47+
#if defined(CONFIG_MMU)
48+
MMU_ALIGN;
49+
#else
50+
MPU_ALIGN(_nocache_load_ram_size);
51+
#endif
52+
_nocache_load_ram_end = .;
2953
_nocache_ram_end = .;
3054
} GROUP_DATA_LINK_IN(RAMABLE_REGION, ROMABLE_REGION)
55+
_nocache_load_ram_size = _nocache_load_ram_end - _nocache_load_ram_start;
56+
_nocache_load_rom_start = LOADADDR(_NOCACHE_LOAD_SECTION_NAME);
3157
_nocache_ram_size = _nocache_ram_end - _nocache_ram_start;
32-
_nocache_load_start = LOADADDR(_NOCACHE_SECTION_NAME);

include/zephyr/linker/linker-defs.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,21 @@ extern char __sg_size[];
237237
* with a MPU. Start and end will be aligned for memory management/protection
238238
* hardware for the target architecture.
239239
*
240-
* All the functions with '__nocache' keyword will be placed into this
241-
* section.
240+
* All the variables with '__nocache' keyword will be placed into the nocache
241+
* section, variables with '__nocache_load' keyword will be placed into the
242+
* nocache section that is loaded from ROM.
242243
*/
243244
#ifdef CONFIG_NOCACHE_MEMORY
244245
extern char _nocache_ram_start[];
245246
extern char _nocache_ram_end[];
246247
extern char _nocache_ram_size[];
247-
extern char _nocache_load_start[];
248+
extern char _nocache_noload_ram_start[];
249+
extern char _nocache_noload_ram_end[];
250+
extern char _nocache_noload_ram_size[];
251+
extern char _nocache_load_ram_start[];
252+
extern char _nocache_load_ram_end[];
253+
extern char _nocache_load_ram_size[];
254+
extern char _nocache_load_rom_start[];
248255
#endif /* CONFIG_NOCACHE_MEMORY */
249256

250257
/* Memory owned by the kernel. Start and end will be aligned for memory

include/zephyr/linker/section_tags.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@
5353

5454
#if defined(CONFIG_NOCACHE_MEMORY)
5555
#define __nocache __in_section_unique(_NOCACHE_SECTION_NAME)
56+
#define __nocache_load __in_section_unique(_NOCACHE_LOAD_SECTION_NAME)
5657
#define __nocache_noinit __nocache
5758
#else
5859
#define __nocache
60+
#define __nocache_load
5961
#define __nocache_noinit __noinit
6062
#endif /* CONFIG_NOCACHE_MEMORY */
6163

include/zephyr/linker/sections.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777

7878
#ifdef CONFIG_NOCACHE_MEMORY
7979
#define _NOCACHE_SECTION_NAME nocache
80+
#define _NOCACHE_LOAD_SECTION_NAME nocache_load
8081
#endif
8182

8283
/* Symbol table section */

kernel/init.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,9 +248,8 @@ void z_bss_zero(void)
248248
((uintptr_t) &__gcov_bss_end - (uintptr_t) &__gcov_bss_start));
249249
#endif /* CONFIG_COVERAGE_GCOV */
250250
#ifdef CONFIG_NOCACHE_MEMORY
251-
z_early_memset(&_nocache_ram_start, 0,
252-
(uintptr_t) &_nocache_ram_end
253-
- (uintptr_t) &_nocache_ram_start);
251+
z_early_memset(&_nocache_ram_start, 0,
252+
(uintptr_t)&_nocache_ram_end - (uintptr_t)&_nocache_ram_start);
254253
#endif
255254
}
256255

kernel/xip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ void z_data_copy(void)
3333
#endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */
3434
#ifdef CONFIG_ARCH_HAS_NOCACHE_MEMORY_SUPPORT
3535
#if CONFIG_NOCACHE_MEMORY
36-
z_early_memcpy(&_nocache_ram_start, &_nocache_load_start,
37-
(uintptr_t) &_nocache_ram_size);
36+
z_early_memcpy(&_nocache_load_ram_start, &_nocache_load_rom_start,
37+
(uintptr_t) &_nocache_load_ram_size);
3838
#endif /* CONFIG_NOCACHE_MEMORY */
3939
#endif /* CONFIG_ARCH_HAS_NOCACHE_MEMORY_SUPPORT */
4040
#if DT_NODE_HAS_STATUS_OKAY(DT_CHOSEN(zephyr_ccm))

0 commit comments

Comments
 (0)