Skip to content

Commit 728530e

Browse files
committed
fix(linker): add data no copy section for boot related vars
Signed-off-by: Daniel Oliveira <[email protected]>
1 parent cfe1677 commit 728530e

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

src/arch/armv8/aarch32/boot.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
add \rd, \rd, r1
1717
.endm
1818

19-
.data
19+
.section .datanocopy
2020
.balign 4
2121
/**
2222
* barrier is used to minimal synchronization in boot - other cores wait for bsp to set it.
@@ -108,7 +108,7 @@ _reset_handler:
108108
* which later will turn on all the others. Therefore, there is no concurrency when setting
109109
* CPU_MASTER and no atomic operations are needed.
110110
*/
111-
.pushsection .data
111+
.pushsection .datanocopy
112112
_master_set:
113113
.4byte 0
114114
.popsection

src/arch/armv8/cpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <platform.h>
99
#include <arch/sysregs.h>
1010

11-
cpuid_t CPU_MASTER __attribute__((section(".data")));
11+
cpuid_t CPU_MASTER __attribute__((section(".datanocopy")));
1212

1313
/* Perform architecture dependent cpu cores initializations */
1414
void cpu_arch_init(cpuid_t cpuid, paddr_t load_addr)

src/arch/riscv/cpu.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <arch/sbi.h>
99
#include <platform.h>
1010

11-
cpuid_t CPU_MASTER __attribute__((section(".data")));
11+
cpuid_t CPU_MASTER __attribute__((section(".datanocopy")));
1212

1313
/* Perform architecture dependent cpu cores initializations */
1414
void cpu_arch_init(cpuid_t cpuid, paddr_t load_addr)

src/core/mem.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ extern uint8_t _image_start, _image_load_end, _image_end, _vm_image_start, _vm_i
2020
struct list page_pool_list;
2121

2222
/* The address where the Bao image is loaded in memory */
23-
vaddr_t img_addr __attribute__((section(".data")));
23+
vaddr_t img_addr __attribute__((section(".datanocopy")));
2424
/* The address where the data section is loaded in memory */
25-
vaddr_t data_addr __attribute__((section(".data")));
25+
vaddr_t data_addr __attribute__((section(".datanocopy")));
2626

2727
static bool pp_bitmap_alloc(size_t pool_num_pages, bitmap_t** bitmap)
2828
{

src/linker.ld

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,25 @@ SECTIONS
5656
_ipi_cpumsg_handlers_id_end = .;
5757
}
5858

59-
.pad_load : {
59+
_image_load_end = .;
60+
61+
.datanocopy : ALIGN(PAGE_SIZE) {
62+
/**
63+
* This section holds data initialized and used during early stages of the boot that can't
64+
* be later rewritten during the copy of data sections from non-volatile memory
65+
*/
66+
*(.datanocopy)
6067
/**
61-
* This section ensures the loadable portion of the image (_image_load_end) is page-aligned
62-
* by adding padding if necessary. The BYTE(0x00) forces this section to be PROGBITS rather
63-
* than NOBITS, ensuring any padding bytes are actually written to the file up to the align
68+
* Ensure the loadable portion of the image (_image_load_end) is page-aligned by adding
69+
* padding if necessary.
6470
*/
65-
BYTE(0x00)
66-
. = ALIGN(PAGE_SIZE);
71+
. = ALIGN(PAGE_SIZE);
6772
}
6873

69-
_image_load_end = .;
70-
7174
#ifdef MEM_NON_UNIFIED
7275
/* Save the current location counter (VMA) and switch to LMA for .vm_images */
7376
_vma_before_vm_images = .;
74-
_image_load_end = _data_lma_start + (_image_load_end - _data_vma_start);
77+
_image_load_end = ALIGN((_data_lma_start + (_image_load_end - _data_vma_start)), PAGE_SIZE);
7578
. = _image_load_end;
7679
#endif
7780

0 commit comments

Comments
 (0)