zephyr/kernel/xip.c

73 lines
2.1 KiB
C
Raw Normal View History

/*
* Copyright (c) 2010-2014 Wind River Systems, Inc.
* Copyright (c) 2020 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <kernel.h>
#include <string.h>
#include <linker/linker-defs.h>
#ifdef CONFIG_STACK_CANARIES
extern volatile uintptr_t __stack_chk_guard;
#endif /* CONFIG_STACK_CANARIES */
/**
* @brief Copy the data section from ROM to RAM
*
* This routine copies the data section from ROM to RAM.
*/
void z_data_copy(void)
{
linker: align __data_ram/rom_start/end linker symbol names Cleanup and preparation commit for linker script generator. Zephyr linker scripts provides start and end symbols for each section, and sometimes even size and LMA start symbols. Generally, start and end symbols uses the following pattern, as: Section name: foo Section start symbol: __foo_start Section end symbol: __foo_end However, this pattern is not followed consistently. To allow for linker script generation and ensure consistent naming of symbols then the following pattern is introduced consistently to allow for cleaner linker script generation. Section name: foo Section start symbol: __foo_start Section end symbol: __foo_end Section size symbol: __foo_size Section LMA start symbol: __foo_load_start This commit aligns the symbols for _data_ram/rom to other symbols and in such a way they follow consistent pattern which allows for linker script and scatter file generation. The symbols are named according to the section name they describe. Section name is `data` A new group named data_region is introduced which instead spans all the input and output sections that was previously covered by __data_ram_start, __data_ram_end, and __data_rom_start. The following symbols are aligned in this commit: - __data_ram_start -> __data_region_start - __data_ram_end -> __data_region_end - __data_rom_start -> __data_region_load_start The following new symbols are introduced so that the data section is aligned with other sections: - __data_end - __data_start value identical to __data_region_start but describes start of the section. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2021-05-22 03:21:52 +08:00
(void)memcpy(&__data_region_start, &__data_region_load_start,
__data_region_end - __data_region_start);
#ifdef CONFIG_ARCH_HAS_RAMFUNC_SUPPORT
(void)memcpy(&__ramfunc_start, &__ramfunc_load_start,
(uintptr_t) &__ramfunc_size);
#endif /* CONFIG_ARCH_HAS_RAMFUNC_SUPPORT */
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_ccm), okay)
(void)memcpy(&__ccm_data_start, &__ccm_data_rom_start,
__ccm_data_end - __ccm_data_start);
#endif
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_itcm), okay)
(void)memcpy(&__itcm_start, &__itcm_load_start,
(uintptr_t) &__itcm_size);
#endif
#if DT_NODE_HAS_STATUS(DT_CHOSEN(zephyr_dtcm), okay)
(void)memcpy(&__dtcm_data_start, &__dtcm_data_load_start,
__dtcm_data_end - __dtcm_data_start);
#endif
#ifdef CONFIG_CODE_DATA_RELOCATION
extern void data_copy_xip_relocation(void);
data_copy_xip_relocation();
#endif /* CONFIG_CODE_DATA_RELOCATION */
#ifdef CONFIG_USERSPACE
#ifdef CONFIG_STACK_CANARIES
/* stack canary checking is active for all C functions.
* __stack_chk_guard is some uninitialized value living in the
* app shared memory sections. Preserve it, and don't make any
* function calls to perform the memory copy. The true canary
* value gets set later in z_cstart().
*/
uintptr_t guard_copy = __stack_chk_guard;
uint8_t *src = (uint8_t *)&_app_smem_rom_start;
uint8_t *dst = (uint8_t *)&_app_smem_start;
uint32_t count = _app_smem_end - _app_smem_start;
guard_copy = __stack_chk_guard;
while (count > 0) {
*(dst++) = *(src++);
count--;
}
__stack_chk_guard = guard_copy;
#else
(void)memcpy(&_app_smem_start, &_app_smem_rom_start,
_app_smem_end - _app_smem_start);
#endif /* CONFIG_STACK_CANARIES */
#endif /* CONFIG_USERSPACE */
}