Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEMPORARY] Change CONFIG_XIP_ELF to run from RAM (temporary changes) #6536

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/examples/hello/hello_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,15 @@
* hello_main
****************************************************************************/

__attribute__ ((__noinline__))
void * get_pc () { return __builtin_return_address(0); }

#ifdef CONFIG_BUILD_KERNEL
int main(int argc, FAR char *argv[])
#else
int hello_main(int argc, char *argv[])
#endif
{
printf("Hello, World!!\n");
printf("Hello, World!!, pc : %p\n", get_pc());
return 0;
}
4 changes: 2 additions & 2 deletions build/configs/rtl8730e/loadable_ext_ddr/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CONFIG_NUM_APPS=1
CONFIG_SUPPORT_COMMON_BINARY=y
CONFIG_COMMON_BINARY_VERSION="200204"
CONFIG_COMMON_BINARY_NAME="common"
CONFIG_COMMON_BIN_STATIC_RAMSIZE=524288
CONFIG_COMMON_BIN_STATIC_RAMSIZE=1048576
CONFIG_NUM_L2_PER_APP=4
CONFIG_BUILD_PROTECTED=y
CONFIG_BUILD_2PASS=y
Expand Down Expand Up @@ -1743,7 +1743,7 @@ CONFIG_APP1_INFO=y
CONFIG_APP1_BIN_NAME="app1"
CONFIG_APP1_BIN_TYPE="ELF"
CONFIG_APP1_BIN_VER=190412
CONFIG_APP1_BIN_DYN_RAMSIZE=5242880
CONFIG_APP1_BIN_DYN_RAMSIZE=20971520
CONFIG_APP1_BIN_LOADING_PRIORITY="LOW"
CONFIG_APP1_MAIN_STACKSIZE=8192
CONFIG_APP1_MAIN_PRIORITY=180
Expand Down
53 changes: 34 additions & 19 deletions build/configs/rtl8730e/loadable_ext_psram/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ CONFIG_NUM_APPS=1
CONFIG_SUPPORT_COMMON_BINARY=y
CONFIG_COMMON_BINARY_VERSION="200204"
CONFIG_COMMON_BINARY_NAME="common"
CONFIG_COMMON_BIN_STATIC_RAMSIZE=524288
CONFIG_COMMON_BIN_STATIC_RAMSIZE=1048576
CONFIG_NUM_L2_PER_APP=4
CONFIG_BUILD_PROTECTED=y
CONFIG_BUILD_2PASS=y
Expand Down Expand Up @@ -118,6 +118,7 @@ CONFIG_ARCH_HAVE_TICKSUPPRESS=y
#
# CONFIG_ARCH_HAVE_DABORTSTACK is not set
CONFIG_SW_STACK_OVERFLOW_DETECTION=y
# CONFIG_STACK_OVERFLOW_PROTECTION_DISABLE is not set
CONFIG_SYSTEM_REBOOT_REASON=y

#
Expand Down Expand Up @@ -183,6 +184,7 @@ CONFIG_AMEBASMART_I2S2=y
# CONFIG_AMEBASMART_I2S3 is not set
# CONFIG_AMEBASMART_I2S_RX is not set
CONFIG_AMEBASMART_I2S_TX=y
CONFIG_AMEBASMART_I2S_TXCL=32

#
# Realtek RTL8730E WIFI Support
Expand Down Expand Up @@ -316,11 +318,15 @@ CONFIG_FLASH_STATUS_BITS=0x28
CONFIG_FLASH_VSTART=0x8000000
CONFIG_TRPK_CONTAINS_MULTIPLE_BINARY=y
CONFIG_FLASH_VSTART_LOADABLE=0xe000000
# CONFIG_RTK_DATA_BINARY_TO_EXT_FLASH is not set
CONFIG_BOARD_FLASH_16M=y
# CONFIG_BOARD_FLASH_32M is not set
CONFIG_SECOND_FLASH_START_ADDR=0x0A000000
CONFIG_RTL8730E_BOARD_REVISION=5
# CONFIG_RAM_DDR is not set
CONFIG_RAM_PSRAM=y
CONFIG_USERFS_MNTPT="/mnt0"
CONFIG_USERFS_EXT_MNTPT="/mnt"

#
# SPI Flash driver
Expand All @@ -330,6 +336,14 @@ CONFIG_AMEBASMART_FLASH_CAPACITY=0x1000000
CONFIG_AMEBASMART_FLASH_PAGE_SIZE=256
CONFIG_AMEBASMART_FLASH_BLOCK_SIZE=4096
CONFIG_AMEBASMART_SECURE_WORLD_ADDRESS=0x70383020

#
# Realtek RTL8730E KM4 IPC Logging
#
CONFIG_RTL8730E_KM4_LOGTASK_PRIO=100
CONFIG_RTL8730E_KM4_LOGTASK_STACK=512
CONFIG_KM4_MAX_LOG_QUEUE_SIZE=5
CONFIG_KM4_MAX_LOG_BUFFER_SIZE=256
CONFIG_ARCH_BOARD_HAVE_FLASH=y

#
Expand All @@ -341,7 +355,6 @@ CONFIG_FLASH_PART_SIZE="60,40,12,400,1844,5404,684,1844,5404,684,8,"
CONFIG_FLASH_PART_TYPE="none,none,none,none,kernel,bin,bin,kernel,bin,bin,bootparam,"
CONFIG_FLASH_PART_NAME="bl1,reserved,ftl,ss,kernel,common,app1,kernel,common,app1,bootparam,"
CONFIG_ARCH_BOARD_HAVE_SECOND_FLASH=y
CONFIG_SECOND_FLASH_START_ADDR=0x0A000000

#
# Second Flash Partition Options
Expand Down Expand Up @@ -408,12 +421,9 @@ CONFIG_PREALLOC_TIMERS=8
#
CONFIG_SPINLOCK=y
CONFIG_INIT_ENTRYPOINT=y
CONFIG_IRQCOUNT=y
CONFIG_SCHED_RESUMESCHEDULER=y
CONFIG_SMP=y
CONFIG_CPU_GATING=y
CONFIG_CPU_HOTPLUG=y
CONFIG_SMP_NCPUS=2
# CONFIG_IRQCOUNT is not set
# CONFIG_SCHED_RESUMESCHEDULER is not set
# CONFIG_SMP is not set
CONFIG_RR_INTERVAL=10
CONFIG_TASK_NAME_SIZE=31
CONFIG_MAX_TASKS=128
Expand Down Expand Up @@ -554,22 +564,19 @@ CONFIG_AUDIO_KEYWORD_DETECT=y
# CONFIG_AUDIO_NULL is not set
# CONFIG_AUDIO_CX20921 is not set
CONFIG_AUDIO_ALC1019=y
# CONFIG_AUDIO_SYU645B is not set
# CONFIG_AUDIO_TAS5749 is not set
# CONFIG_DRIVERS_VIDEO is not set

#
# AI SoC devices
#
# CONFIG_NDP120 is not set

#
# LCD Driver Support
#
# CONFIG_LCD is not set
# CONFIG_LCD_ST7701 is not set
# CONFIG_LCD_ST7701SN is not set
# CONFIG_LCD_ST7785 is not set
# CONFIG_LCD_ST7789 is not set
# CONFIG_LCD_LANDSCAPE is not set
# CONFIG_LCD_PORTRAIT is not set
# CONFIG_LCD_RPORTRAIT is not set
# CONFIG_LCD_RLANDSCAPE is not set
# CONFIG_LCD_ILI9341 is not set
CONFIG_BCH=y
CONFIG_RTC=y
# CONFIG_RTC_DATETIME is not set
Expand Down Expand Up @@ -958,6 +965,7 @@ CONFIG_NET_SECURITY_TLS=y
CONFIG_TLS_WITH_HW_ACCEL=y
CONFIG_TLS_MPI_MAX_SIZE=512
# CONFIG_TLS_HAVE_NO_TIME_DATE is not set
# CONFIG_MBEDTLS_PKCS5_C is not set

#
# HW Options
Expand Down Expand Up @@ -1045,7 +1053,9 @@ CONFIG_AUDIO_EXCLUDE_REWIND=y
CONFIG_MEDIA=y
CONFIG_MEDIA_PLAYER=y
CONFIG_MEDIA_PLAYER_STACKSIZE=4096
CONFIG_MEDIA_PLAYER_THREAD_PRIORITY=100
CONFIG_MEDIA_PLAYER_OBSERVER_STACKSIZE=2048
CONFIG_MEDIA_PLAYER_OBSERVER_THREAD_PRIORITY=100
CONFIG_INPUT_DATASOURCE_STACKSIZE=4096
CONFIG_HTTPSOURCE_DOWNLOAD_BUFFER_SIZE=4096
CONFIG_HTTPSOURCE_DOWNLOAD_BUFFER_THRESHOLD=2048
Expand Down Expand Up @@ -1074,7 +1084,7 @@ CONFIG_BUFFER_DATASOURCE_STREAM_BUFFER_SIZE=4096
CONFIG_BUFFER_DATASOURCE_STREAM_BUFFER_THRESHOLD=1
CONFIG_HANDLER_STREAM_BUFFER_SIZE=4096
CONFIG_HANDLER_STREAM_BUFFER_THRESHOLD=2048
# CONFIG_AUDIO_CODEC is not set
CONFIG_HANDLER_STREAM_THREAD_PRIORITY=100

#
# File Systems
Expand Down Expand Up @@ -1415,6 +1425,7 @@ CONFIG_LIBCXX_HAVE_LIBSUPCXX=y
#
# External Libraries
#
# CONFIG_AUDIO_CODEC is not set
# CONFIG_AVS_DEVICE_SDK is not set
# CONFIG_AWS_SDK is not set
# CONFIG_NETUTILS_CODECS is not set
Expand Down Expand Up @@ -1482,6 +1493,7 @@ CONFIG_STRESS_TOOL=y
# CONFIG_EXTERNAL_TFMICRO is not set
# CONFIG_EXTERNAL_CMSIS_DSP is not set
# CONFIG_EXTERNAL_CMSIS_NN is not set
# CONFIG_EXTERNAL_ONERT_MICRO is not set

#
# Binary Loader
Expand Down Expand Up @@ -1519,6 +1531,7 @@ CONFIG_BUILTIN_APPS=y
#
# Examples
#
# CONFIG_EXAMPLES_SOUNDPLAYER is not set
# CONFIG_EXAMPLES_AVS_TEST is not set
# CONFIG_EXAMPLES_AWS is not set
# CONFIG_EXAMPLES_BLE_PERFS is not set
Expand Down Expand Up @@ -1557,6 +1570,7 @@ CONFIG_EXAMPLES_HELLOXX=y
# CONFIG_EXAMPLES_KERNEL_SAMPLE is not set
# CONFIG_EXAMPLES_KERNEL_UPDATE is not set
# CONFIG_EXAMPLES_LCD is not set
# CONFIG_EXAMPLES_LED is not set

#
# Libcoap
Expand Down Expand Up @@ -1607,7 +1621,6 @@ CONFIG_EXAMPLES_HELLOXX=y
# CONFIG_EXAMPLES_SMART is not set
# CONFIG_EXAMPLES_SMART_TEST is not set
# CONFIG_EXAMPLES_SMARTFS_POWERCUT is not set
# CONFIG_TESTING_SMP is not set
# CONFIG_EXAMPLES_ST_THINGS is not set
# CONFIG_EXAMPLES_TESTCASE is not set

Expand All @@ -1618,7 +1631,9 @@ CONFIG_EXAMPLES_HELLOXX=y
# CONFIG_EXAMPLES_TLS_SELFTEST is not set
# CONFIG_EXAMPLES_TLS_SERVER is not set
# CONFIG_UART_HW_TEST is not set
# CONFIG_EXAMPLES_UART_LOOPBACK is not set
# CONFIG_EXAMPLES_VIRTKEY is not set
# CONFIG_EXAMPLES_WAKEREC is not set
# CONFIG_EXAMPLES_WAVE_GEN is not set
# CONFIG_EXAMPLES_WEBSERVER is not set
# CONFIG_EXAMPLES_WEBSERVER_TEST is not set
Expand Down
46 changes: 24 additions & 22 deletions build/configs/rtl8730e/scripts/xipelf/userspace_all.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
SECTIONS
{
. = ORIGIN(uflash);
_text_start_flash = ABSOLUTE(.);

.text ORIGIN(uflash) :
.text :
{
_stext_flash = . ;
/* Place holder to keep the heap object at the top
Expand All @@ -11,6 +13,9 @@ SECTIONS
*/
LONG(0);
KEEP(*(.userspace))

. = ALIGN(32);

*(.text)
*(.text.*)
*(.gnu.warning)
Expand All @@ -27,31 +32,24 @@ SECTIONS
*(.init) /* Old ABI */
*(.fini) /* Old ABI */
_etext_flash = . ;
} > uflash

*(.ARM.extab*)

.ARM.extab : {
*(.ARM.extab*)
} > uflash
. = ALIGN(32);

__fexidx_start = ABSOLUTE(.);
.ARM.exidx : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} > uflash
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;

__fexidx_end = ABSOLUTE(.);
. = ALIGN(32);

.rodata :
{
_srodata = . ;
*(.rodata)
*(.rodata1)
*(.rodata.*)
*(.gnu.linkonce.r*)
_erodata = . ;
_eronly = .;
} > uflash

/* C++ support. For each global and static local C++ object,
* GCC creates a small subroutine to construct the object. Pointers
Expand All @@ -61,26 +59,30 @@ SECTIONS
* stored in .dtors.
*/

.ctors :
{
. = ALIGN(32);

_sctors = . ;
*(.ctors) /* Old ABI: Unallocated */
*(.init_array) /* New ABI: Allocated */
_ectors = . ;
} > uflash

.dtors :
{
. = ALIGN(32);

_sdtors = . ;
*(.dtors) /* Old ABI: Unallocated */
*(.fini_array) /* New ABI: Allocated */
_edtors = . ;
} > uflash

_sdata_app1 = ABSOLUTE(.);
} > usram AT > uflash



_sdata_app = ABSOLUTE(.);
_sdata_app2 = ABSOLUTE(.);

.data :
{
_sdata_app = LOADADDR(.data);
_sdata = . ;
LONG(0);
*(.curapp)
Expand Down
2 changes: 1 addition & 1 deletion loadable_apps/loadable.mk
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ endif

ifeq ($(CONFIG_XIP_ELF),y)
$(BIN): $(OBJS)
$(Q) $(LD) -T $(USER_BIN_DIR)/$@_0.ld -T $(TOPDIR)/../build/configs/$(CONFIG_ARCH_BOARD)/scripts/xipelf/userspace_all.ld -e main -o $@ $(ARCHCRT0OBJ) $^ --start-group $(LIBGCC) $(LIBSUPXX) --end-group -R $(USER_BIN_DIR)/$(CONFIG_COMMON_BINARY_NAME)
$(Q) $(LD) -T $(USER_BIN_DIR)/$@_0.ld -T $(TOPDIR)/../build/configs/$(CONFIG_ARCH_BOARD)/scripts/xipelf/userspace_all.ld -e main -o $@ $(ARCHCRT0OBJ) $^ --start-group $(LIBGCC) $(LIBSUPXX) --end-group -R $(USER_BIN_DIR)/$(CONFIG_COMMON_BINARY_NAME) -Map $(BIN).map

undefsym : $(OBJS)
$(Q) $(LD) $(LDELFFLAGS) -o $(USER_BIN_DIR)/$(BIN).relelf $(ARCHCRT0OBJ) $^ --start-group $(LIBGCC) --end-group
Expand Down
2 changes: 1 addition & 1 deletion os/binfmt/binfmt_pgtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void binfmt_setup_app_pgtable(struct binary_s *binp)
#else // ELF

/* map entire flash region of app as rw */
mmu_map_app_region(binp->binary_idx, l1tbl, binp->flash_region_start, binp->flash_region_end - binp->flash_region_start, true, true);
//mmu_map_app_region(binp->binary_idx, l1tbl, binp->flash_region_start, binp->flash_region_end - binp->flash_region_start, true, true);

/* map entire RAM region of app as rx */
mmu_map_app_region(binp->binary_idx, l1tbl, binp->ram_region_start, binp->ram_region_end - binp->ram_region_start, false, true);
Expand Down
15 changes: 14 additions & 1 deletion os/binfmt/libxipelf/xipelf.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ static int xipelf_loadbinary(FAR struct binary_s *binp)
binp->sections[BIN_TEXT] = (uint32_t)uspace.text_start;
binp->flash_region_start = (uint32_t)uspace.text_start - uspace_offset + 4;
binp->flash_region_end = (uint32_t)uspace.flash_end;
binp->ram_region_start = (uint32_t)uspace.ram_start;
binp->ram_region_start = (uint32_t)uspace.text_start;
binp->ram_region_end = (uint32_t)uspace.ram_end;
binp->sizes[BIN_TEXT] = binp->flash_region_end - binp->flash_region_start;

Expand All @@ -116,12 +116,25 @@ static int xipelf_loadbinary(FAR struct binary_s *binp)
binp->sizes[BIN_BSS] = uspace.bss_end - uspace.bss_start;

/* copy the data... */
lldbg("data start in flash : %x\n", uspace.data_start_in_flash);
lldbg("data start in ram : %x\n", uspace.data_start_in_ram);
lldbg("data end in ram : %x\n", uspace.data_end_in_ram);
uint8_t *orig_data = uspace.data_start_in_flash;
for (uint8_t *data = uspace.data_start_in_ram; data < (uint8_t *)uspace.data_end_in_ram; data++) {
*data = *orig_data;
orig_data++;
}

/* copy all text... */
uint8_t *orig_text = uspace.text_start_in_flash;
lldbg("text start : %x\n", uspace.text_start);
lldbg("text end : %x\n", uspace.ectors);
for (uint8_t *text = uspace.text_start; text < (uint8_t *)uspace.ectors; text++) {
*text = *orig_text;
//lldbg("text : %02x\n", *orig_text);
orig_text++;
}

binp->sections[BIN_DATA] = (uint32_t)uspace.data_start_in_ram;
binp->sizes[BIN_DATA] = uspace.data_end_in_ram - uspace.data_start_in_ram;

Expand Down
1 change: 1 addition & 0 deletions os/include/tinyara/userspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct userspace_s {
void * data_start_in_ram;
void * data_end_in_ram;
void * data_start_in_flash;
void * text_start_in_flash;
void * heap_start;
void * heap_end;
void * sctors;
Expand Down
2 changes: 2 additions & 0 deletions os/userspace/up_userspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ extern uint32_t _ectors;
extern uint32_t _eapp_flash;
extern uint32_t _sapp_ram;
extern uint32_t _eapp_ram;
extern uint32_t _text_start_flash;

extern int main(int argc, char **argv);
#endif
Expand Down Expand Up @@ -95,6 +96,7 @@ const struct userspace_s userspace __attribute__((section(".userspace"))) = {
.flash_end = &_eapp_flash,
.ram_start = &_sapp_ram,
.ram_end = &_eapp_ram,
.text_start_in_flash = &_text_start_flash,
#ifndef __COMMON_BINARY__
.entry = main,
#endif
Expand Down