diff --git a/arch/xtensa/Kconfig b/arch/xtensa/Kconfig index 0bd1bcc3bb5..663276c727f 100644 --- a/arch/xtensa/Kconfig +++ b/arch/xtensa/Kconfig @@ -14,6 +14,7 @@ config ARCH_CHIP_ESP32 select ARCH_FAMILY_LX6 select XTENSA_HAVE_INTERRUPTS select ARCH_HAVE_FPU + select ARCH_HAVE_MPU select ARCH_HAVE_MULTICPU select ARCH_HAVE_TEXT_HEAP select ARCH_HAVE_SDRAM diff --git a/arch/xtensa/src/esp32/Kconfig b/arch/xtensa/src/esp32/Kconfig index b6032cae9fb..98db1623bc4 100644 --- a/arch/xtensa/src/esp32/Kconfig +++ b/arch/xtensa/src/esp32/Kconfig @@ -1601,6 +1601,16 @@ config ESP32_PARTITION_TABLE_OFFSET default 0x8000 depends on ESP32_APP_FORMAT_LEGACY +if BUILD_PROTECTED + +config ESP32_USER_IMAGE_OFFSET + hex "User image offset" + default 0x90000 + ---help--- + Offset in SPI Flash for flashing the User application firmware image. + +endif + source "arch/xtensa/src/esp32/Kconfig.security" endmenu # Application Image Configuration diff --git a/arch/xtensa/src/esp32/Make.defs b/arch/xtensa/src/esp32/Make.defs index 2d6a50ae1c2..7b8a1313dc8 100644 --- a/arch/xtensa/src/esp32/Make.defs +++ b/arch/xtensa/src/esp32/Make.defs @@ -25,7 +25,7 @@ include common/Make.defs HEAD_CSRC = esp32_start.c esp32_wdt.c -# Required ESP32 files (arch/xtensa/src/lx6) +# Required ESP32 files (arch/xtensa/src/esp32) CHIP_CSRCS = esp32_allocateheap.c esp32_clockconfig.c esp32_gpio.c CHIP_CSRCS += esp32_systemreset.c esp32_resetcause.c @@ -37,6 +37,10 @@ ifneq ($(CONFIG_ARCH_IDLE_CUSTOM),y) CHIP_CSRCS += esp32_idle.c endif +ifeq ($(CONFIG_BUILD_PROTECTED),y) +CHIP_CSRCS += esp32_userspace.c +endif + ifeq ($(CONFIG_SCHED_TICKLESS),y) CHIP_CSRCS += esp32_tickless.c else diff --git a/arch/xtensa/src/esp32/esp32_allocateheap.c b/arch/xtensa/src/esp32/esp32_allocateheap.c index 5a7b32e42ad..10fe37606d2 100644 --- a/arch/xtensa/src/esp32/esp32_allocateheap.c +++ b/arch/xtensa/src/esp32/esp32_allocateheap.c @@ -29,9 +29,13 @@ #include #include -#include #include +#include +#include #include +#ifdef CONFIG_MM_KERNEL_HEAP +#include +#endif #include #ifdef CONFIG_ESP32_SPIRAM_BANKSWITCH_ENABLE @@ -55,29 +59,83 @@ * Description: * This function will be called to dynamically set aside the heap region. * - * For the kernel build (CONFIG_BUILD_KERNEL=y) with both kernel- and - * user-space heaps (CONFIG_MM_KERNEL_HEAP=y), this function provides the - * size of the unprotected, user-space heap. + * For the kernel build (CONFIG_BUILD_KERNEL=y) with both kernel and + * userspace heaps (CONFIG_MM_KERNEL_HEAP=y), this function provides the + * size of the unprotected, userspace heap. * - * If a protected kernel-space heap is provided, the kernel heap must be + * If a protected kernel space heap is provided, the kernel heap must be * allocated (and protected) by an analogous up_allocate_kheap(). * ****************************************************************************/ void up_allocate_heap(void **heap_start, size_t *heap_size) { +#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP) + uintptr_t ubase = USERSPACE->us_dataend; + uintptr_t utop = USERSPACE->us_heapend; + size_t usize = utop - ubase; + + minfo("Heap: start=%" PRIxPTR " end=%" PRIxPTR " size=%zu\n", + ubase, utop, usize); + + board_autoled_on(LED_HEAPALLOCATE); + + /* Return the userspace heap settings */ + + *heap_start = (void *)ubase; + *heap_size = usize; + + /* Allow user-mode access to the user heap memory */ + +#else board_autoled_on(LED_HEAPALLOCATE); *heap_start = (void *)&_sheap; DEBUGASSERT(HEAP_REGION1_END > (uintptr_t)*heap_start); *heap_size = (size_t)(HEAP_REGION1_END - (uintptr_t)*heap_start); +#endif /* CONFIG_BUILD_PROTECTED && CONFIG_MM_KERNEL_HEAP */ } +/**************************************************************************** + * Name: up_allocate_kheap + * + * Description: + * This function will be called to dynamically set aside the heap region. + * + * For the kernel build (CONFIG_BUILD_PROTECTED=y) with both kernel and + * userspace heaps (CONFIG_MM_KERNEL_HEAP=y), this function allocates + * (and protects) the kernel space heap. + * + ****************************************************************************/ + +#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_MM_KERNEL_HEAP) && \ + defined(__KERNEL__) +void up_allocate_kheap(void **heap_start, size_t *heap_size) +{ + /* These values come from the linker scripts (kernel-space.ld and + * protected.template.ld). + * Check boards/xtensa/esp32. + */ + + uintptr_t kbase = (uintptr_t)&_sheap; + uintptr_t ktop = KDRAM_0_END; + size_t ksize = ktop - kbase; + + minfo("Heap: start=%" PRIxPTR " end=%" PRIxPTR " size=%zu\n", + kbase, ktop, ksize); + + board_autoled_on(LED_HEAPALLOCATE); + + *heap_start = (void *)kbase; + *heap_size = ksize; +} +#endif /* CONFIG_BUILD_PROTECTED && CONFIG_MM_KERNEL_HEAP */ + /**************************************************************************** * Name: xtensa_add_region * * Description: - * Memory may be added in non-contiguous chunks. Additional chunks are + * Memory may be added in non-contiguous chunks. Additional chunks are * added by calling this function. * ****************************************************************************/ @@ -115,22 +173,38 @@ void xtensa_add_region(void) #ifndef CONFIG_SMP start = (void *)(HEAP_REGION2_START + XTENSA_IMEM_REGION_SIZE); size = (size_t)(uintptr_t)&_eheap - (size_t)start; +#ifdef CONFIG_BUILD_PROTECTED + kmm_addregion(start, size); +#else umm_addregion(start, size); +#endif #else start = (void *)HEAP_REGION2_START; size = (size_t)(HEAP_REGION2_END - HEAP_REGION2_START); +#ifdef CONFIG_BUILD_PROTECTED + kmm_addregion(start, size); +#else umm_addregion(start, size); +#endif start = (void *)HEAP_REGION3_START + XTENSA_IMEM_REGION_SIZE; size = (size_t)(uintptr_t)&_eheap - (size_t)start; +#ifdef CONFIG_BUILD_PROTECTED + kmm_addregion(start, size); +#else umm_addregion(start, size); #endif +#endif #ifndef CONFIG_ESP32_BLE start = (void *)HEAP_REGION0_START; size = (size_t)(HEAP_REGION0_END - HEAP_REGION0_START); +#ifdef CONFIG_BUILD_PROTECTED + kmm_addregion(start, size); +#else umm_addregion(start, size); #endif +#endif #ifdef CONFIG_ESP32_SPIRAM # if defined(CONFIG_HEAP2_BASE) && defined(CONFIG_HEAP2_SIZE) diff --git a/arch/xtensa/src/esp32/esp32_start.c b/arch/xtensa/src/esp32/esp32_start.c index fab28e26a64..420ac161c38 100644 --- a/arch/xtensa/src/esp32/esp32_start.c +++ b/arch/xtensa/src/esp32/esp32_start.c @@ -34,13 +34,16 @@ #include "xtensa.h" #include "xtensa_attr.h" -#include "hardware/esp32_dport.h" -#include "hardware/esp32_rtccntl.h" #include "esp32_clockconfig.h" #include "esp32_region.h" #include "esp32_start.h" #include "esp32_spiram.h" #include "esp32_wdt.h" +#ifdef CONFIG_BUILD_PROTECTED +# include "esp32_userspace.h" +#endif +#include "hardware/esp32_dport.h" +#include "hardware/esp32_rtccntl.h" /**************************************************************************** * Pre-processor Definitions @@ -232,6 +235,17 @@ static noreturn_function void __esp32_start(void) showprogress("B"); + /* For the case of the separate user-/kernel-space build, perform whatever + * platform specific initialization of the user memory is required. + * Normally this just means initializing the user space .data and .bss + * segments. + */ + +#ifdef CONFIG_BUILD_PROTECTED + esp32_userspace(); + showprogress("C"); +#endif + /* Bring up NuttX */ nx_start(); diff --git a/arch/xtensa/src/esp32/esp32_userspace.c b/arch/xtensa/src/esp32/esp32_userspace.c new file mode 100755 index 00000000000..812bbc84ca5 --- /dev/null +++ b/arch/xtensa/src/esp32/esp32_userspace.c @@ -0,0 +1,344 @@ +/**************************************************************************** + * arch/xtensa/src/esp32/esp32_userspace.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include +#include + +#include + +#include + +#include "xtensa_attr.h" +#include "esp32_userspace.h" +#include "hardware/esp32_dport.h" + +#ifdef CONFIG_BUILD_PROTECTED + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define USER_IMAGE_OFFSET CONFIG_ESP32_USER_IMAGE_OFFSET + +#define MMU_BLOCK0_VADDR SOC_DROM_LOW +#define MMU_SIZE 0x320000 +#define MMU_BLOCK50_VADDR (MMU_BLOCK0_VADDR + MMU_SIZE) + +/* Cache MMU block size */ + +#define MMU_BLOCK_SIZE 0x00010000 /* 64 KB */ + +/* Cache MMU address mask (MMU tables ignore bits which are zero) */ + +#define MMU_FLASH_MASK (~(MMU_BLOCK_SIZE - 1)) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct user_image_load_header_s +{ + uintptr_t drom_vma; /* Destination address (VMA) for DROM region */ + uintptr_t drom_lma; /* Flash offset (LMA) for start of DROM region */ + uintptr_t drom_size; /* Size of DROM region */ + uintptr_t irom_vma; /* Destination address (VMA) for IROM region */ + uintptr_t irom_lma; /* Flash offset (LMA) for start of IROM region */ + uintptr_t irom_size; /* Size of IROM region */ +}; + +/**************************************************************************** + * ROM Function Prototypes + ****************************************************************************/ + +extern void cache_read_enable(int cpu); +extern void cache_read_disable(int cpu); +extern void cache_flush(int cpu); +extern unsigned int cache_flash_mmu_set(int cpu_no, int pid, + unsigned int vaddr, + unsigned int paddr, + int psize, int num); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct user_image_load_header_s g_header; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: calc_mmu_pages + * + * Description: + * Calculate the required number of MMU pages for mapping a given region + * from External Flash into Internal RAM. + * + * Input Parameters: + * size - Length of the region to map + * vaddr - Starting External Flash offset to map to Internal RAM + * + * Returned Value: + * None. + * + ****************************************************************************/ + +static inline uint32_t calc_mmu_pages(uint32_t size, uint32_t vaddr) +{ + return (size + (vaddr - (vaddr & MMU_FLASH_MASK)) + MMU_BLOCK_SIZE - 1) / + MMU_BLOCK_SIZE; +} + +/**************************************************************************** + * Name: configure_flash_mmu + * + * Description: + * Configure the External Flash MMU and Cache for enabling access to code + * and read-only data of the userspace image. + * + * Input Parameters: + * None. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +static noinline_function IRAM_ATTR void configure_flash_mmu(void) +{ + uint32_t drom_lma_aligned; + uint32_t drom_vma_aligned; + uint32_t drom_page_count; + uint32_t irom_lma_aligned; + uint32_t irom_vma_aligned; + uint32_t irom_page_count; + + size_t partition_offset = USER_IMAGE_OFFSET; + uint32_t app_drom_lma = partition_offset + g_header.drom_lma; + uint32_t app_drom_size = g_header.drom_size; + uint32_t app_drom_vma = g_header.drom_vma; + uint32_t app_irom_lma = partition_offset + g_header.irom_lma; + uint32_t app_irom_size = g_header.irom_size; + uint32_t app_irom_vma = g_header.irom_vma; + + cache_read_disable(0); + cache_flush(0); + + drom_lma_aligned = app_drom_lma & MMU_FLASH_MASK; + drom_vma_aligned = app_drom_vma & MMU_FLASH_MASK; + drom_page_count = calc_mmu_pages(app_drom_size, app_drom_vma); + DEBUGVERIFY(cache_flash_mmu_set(0, 0, drom_vma_aligned, drom_lma_aligned, + 64, (int)drom_page_count)); + DEBUGVERIFY(cache_flash_mmu_set(1, 0, drom_vma_aligned, drom_lma_aligned, + 64, (int)drom_page_count)); + + irom_lma_aligned = app_irom_lma & MMU_FLASH_MASK; + irom_vma_aligned = app_irom_vma & MMU_FLASH_MASK; + irom_page_count = calc_mmu_pages(app_irom_size, app_irom_vma); + DEBUGVERIFY(cache_flash_mmu_set(0, 0, irom_vma_aligned, irom_lma_aligned, + 64, (int)irom_page_count)); + DEBUGVERIFY(cache_flash_mmu_set(1, 0, irom_vma_aligned, irom_lma_aligned, + 64, (int)irom_page_count)); + + cache_read_enable(0); +} + +/**************************************************************************** + * Name: map_flash + * + * Description: + * Map a region of the External Flash memory to Internal RAM. + * + * Input Parameters: + * src_addr - Starting External Flash offset to map to Internal RAM + * size - Length of the region to map + * + * Returned Value: + * None. + * + ****************************************************************************/ + +static noinline_function IRAM_ATTR const void *map_flash(uint32_t src_addr, + uint32_t size) +{ + uint32_t src_addr_aligned; + uint32_t page_count; + + cache_read_disable(0); + cache_flush(0); + + src_addr_aligned = src_addr & MMU_FLASH_MASK; + page_count = calc_mmu_pages(size, src_addr); + DEBUGVERIFY(cache_flash_mmu_set(0, 0, MMU_BLOCK50_VADDR, src_addr_aligned, + 64, (int)page_count)); + + cache_read_enable(0); + + return (void *)(MMU_BLOCK50_VADDR + (src_addr - src_addr_aligned)); +} + +/**************************************************************************** + * Name: load_header + * + * Description: + * Load IROM and DROM information from image header to enable the correct + * configuration of the Flash MMU and Cache. + * + * Input Parameters: + * None. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +static void load_header(void) +{ + size_t length = sizeof(struct user_image_load_header_s); + const uint8_t *data = + (const uint8_t *)map_flash(USER_IMAGE_OFFSET, length); + + DEBUGASSERT(data != NULL); + + memcpy(&g_header, data, length); +} + +/**************************************************************************** + * Name: initialize_data + * + * Description: + * Initialize data sections of the userspace image. + * + * Input Parameters: + * None. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +static void initialize_data(void) +{ + uint8_t *dest; + uint8_t *end; + size_t length = USERSPACE->us_dataend - USERSPACE->us_datastart; + const uint8_t *src = + (const uint8_t *)map_flash(USER_IMAGE_OFFSET + USERSPACE->us_datasource, + length); + + DEBUGASSERT(src != NULL); + + dest = (uint8_t *)USERSPACE->us_datastart; + end = (uint8_t *)USERSPACE->us_dataend; + + while (dest != end) + { + *dest++ = *src++; + } +} + +/**************************************************************************** + * Name: configure_mpu + * + * Description: + * Configure the MPU for kernel/userspace separation. + * + * Input Parameters: + * None. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +static void configure_mpu(void) +{ +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_userspace + * + * Description: + * For the case of the separate user/kernel space build, perform whatever + * platform specific initialization of the user memory is required. + * Normally this just means initializing the userspace .data and .bss + * segments. + * + * Input Parameters: + * None. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +void esp32_userspace(void) +{ + uint8_t *dest; + uint8_t *end; + + /* Load IROM and DROM information from image header */ + + load_header(); + + /* Configure the Flash MMU for enabling access to the userspace image */ + + configure_flash_mmu(); + + /* Clear all of userspace .bss */ + + DEBUGASSERT(USERSPACE->us_bssstart != 0 && USERSPACE->us_bssend != 0 && + USERSPACE->us_bssstart <= USERSPACE->us_bssend); + + dest = (uint8_t *)USERSPACE->us_bssstart; + end = (uint8_t *)USERSPACE->us_bssend; + + while (dest != end) + { + *dest++ = 0; + } + + /* Initialize all of userspace .data */ + + DEBUGASSERT(USERSPACE->us_datasource != 0 && + USERSPACE->us_datastart != 0 && USERSPACE->us_dataend != 0 && + USERSPACE->us_datastart <= USERSPACE->us_dataend); + + initialize_data(); + + /* Configure MPU to grant access to the userspace */ + + configure_mpu(); +} + +#endif /* CONFIG_BUILD_PROTECTED */ diff --git a/arch/xtensa/src/esp32/esp32_userspace.h b/arch/xtensa/src/esp32/esp32_userspace.h new file mode 100755 index 00000000000..4271177dc7e --- /dev/null +++ b/arch/xtensa/src/esp32/esp32_userspace.h @@ -0,0 +1,49 @@ +/**************************************************************************** + * arch/xtensa/src/esp32/esp32_userspace.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_XTENSA_SRC_ESP32_ESP32_USERSPACE_H +#define __ARCH_XTENSA_SRC_ESP32_ESP32_USERSPACE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Functions Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32_userspace + * + * Description: + * For the case of the separate user-/kernel-space build, perform whatever + * platform specific initialization of the user memory is required. + * Normally this just means initializing the user space .data and .bss + * segments. + * + ****************************************************************************/ + +#ifdef CONFIG_BUILD_PROTECTED +void esp32_userspace(void); +#endif + +#endif /* __ARCH_XTENSA_SRC_ESP32_ESP32_USERSPACE_H */ diff --git a/boards/xtensa/esp32/common/kernel/Makefile b/boards/xtensa/esp32/common/kernel/Makefile new file mode 100755 index 00000000000..c29e3c5f71f --- /dev/null +++ b/boards/xtensa/esp32/common/kernel/Makefile @@ -0,0 +1,97 @@ +############################################################################ +# boards/xtensa/esp32/common/kernel/Makefile +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include $(TOPDIR)/Make.defs + +# The entry point name (if none is provided in the .config file) + +CONFIG_INIT_ENTRYPOINT ?= user_start +ENTRYPT = $(patsubst "%",%,$(CONFIG_INIT_ENTRYPOINT)) + +# Get the paths to the libraries and the links script path in format that +# is appropriate for the host OS + +USER_LIBPATHS = $(addprefix -L,$(call CONVERT_PATH,$(addprefix $(TOPDIR)$(DELIM),$(dir $(USERLIBS))))) +USER_LDSCRIPT = -T $(call CONVERT_PATH,$(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld) +USER_LDSCRIPT += -T $(call CONVERT_PATH,$(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)user-space.ld) +USER_HEXFILE += $(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx_user.hex) +USER_BINFILE += $(call CONVERT_PATH,$(TOPDIR)$(DELIM)nuttx_user.bin) + +USER_LDFLAGS = --undefined=$(ENTRYPT) --entry=$(ENTRYPT) $(USER_LDSCRIPT) + +ifeq ($(CONFIG_DEBUG_LINK_MAP),y) +USER_LDFLAGS += --cref -Map="$(TOPDIR)$(DELIM)User.map" +endif + +USER_LDLIBS = $(patsubst lib%,-l%,$(basename $(notdir $(USERLIBS)))) +USER_LIBGCC = "${shell "$(CC)" $(ARCHCPUFLAGS) -print-libgcc-file-name}" + +# Source files + +CSRCS = esp32_userspace.c +COBJS = $(CSRCS:.c=$(OBJEXT)) +OBJS = $(COBJS) + +ifeq ($(LD),$(CC)) + LDSTARTGROUP ?= -Wl,--start-group + LDENDGROUP ?= -Wl,--end-group + USER_LDFLAGS := $(addprefix -Xlinker ,$(USER_LDFLAGS)) + USER_LDFLAGS += $(CFLAGS) +else + LDSTARTGROUP ?= --start-group + LDENDGROUP ?= --end-group +endif + +# Targets: + +all: $(TOPDIR)$(DELIM)nuttx_user.elf +.PHONY: nuttx_user.elf depend clean distclean + +$(COBJS): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +# Create the nuttx_user.elf file containing all of the user-mode code + +nuttx_user.elf: $(OBJS) + $(Q) $(LD) -o $@ $(USER_LDFLAGS) $(USER_LIBPATHS) $(OBJS) $(LDSTARTGROUP) $(USER_LDLIBS) $(LDENDGROUP) $(USER_LIBGCC) + +$(TOPDIR)$(DELIM)nuttx_user.elf: nuttx_user.elf + $(Q) echo "LD: nuttx_user.elf" + $(Q) cp -a nuttx_user.elf $(TOPDIR)$(DELIM)nuttx_user.elf +ifeq ($(CONFIG_INTELHEX_BINARY),y) + $(Q) echo "CP: nuttx_user.hex" + $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O ihex nuttx_user.elf $(USER_HEXFILE) +endif +ifeq ($(CONFIG_RAW_BINARY),y) + $(Q) echo "CP: nuttx_user.bin" + $(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary nuttx_user.elf $(USER_BINFILE) +endif + +.depend: + +depend: .depend + +clean: + $(call DELFILE, nuttx_user.elf) + $(call DELFILE, "$(TOPDIR)$(DELIM)nuttx_user.*") + $(call DELFILE, "$(TOPDIR)$(DELIM)User.map") + $(call CLEAN) + +distclean: clean diff --git a/boards/xtensa/esp32/common/kernel/esp32_userspace.c b/boards/xtensa/esp32/common/kernel/esp32_userspace.c new file mode 100755 index 00000000000..6e292769fa8 --- /dev/null +++ b/boards/xtensa/esp32/common/kernel/esp32_userspace.c @@ -0,0 +1,114 @@ +/**************************************************************************** + * boards/xtensa/esp32/common/kernel/esp32_userspace.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include +#include +#include +#include + +#if defined(CONFIG_BUILD_PROTECTED) && !defined(__KERNEL__) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +#ifndef CONFIG_NUTTX_USERSPACE +# error "CONFIG_NUTTX_USERSPACE not defined" +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* These 'addresses' of these values are setup by the linker script. + * They are not actual uint32_t storage locations! + * They are only used meaningfully in the following way: + * + * - The linker script defines, for example, the symbol_sdata. + * - The declaration extern uint32_t _sdata; makes C happy. C will believe + * that the value _sdata is the address of a uint32_t variable _data + * (it is not!). + * - We can recover the linker value then by simply taking the address of + * of _data. like: uint32_t *pdata = &_sdata; + */ + +extern uint32_t _stext; /* Start of .text */ +extern uint32_t _etext; /* End+1 of .text + .rodata */ +extern const uint32_t _eronly; /* End+1 of read only section */ +extern uint32_t _sdata; /* Start of .data */ +extern uint32_t _edata; /* End+1 of .data */ +extern uint32_t _sbss; /* Start of .bss */ +extern uint32_t _ebss; /* End+1 of .bss */ + +extern uintptr_t *__ld_udram_end; /* End+1 of user ram section */ + +/* This is the user space entry point */ + +int CONFIG_INIT_ENTRYPOINT(int argc, char *argv[]); + +const struct userspace_s userspace locate_data(".userspace") = +{ + /* General memory map */ + + .us_entrypoint = (main_t)CONFIG_INIT_ENTRYPOINT, + .us_textstart = (uintptr_t)&_stext, + .us_textend = (uintptr_t)&_etext, + .us_datasource = (uintptr_t)&_eronly, + .us_datastart = (uintptr_t)&_sdata, + .us_dataend = (uintptr_t)&_edata, + .us_bssstart = (uintptr_t)&_sbss, + .us_bssend = (uintptr_t)&_ebss, + + .us_heapend = (uintptr_t)&__ld_udram_end, + + /* Memory manager heap structure */ + + .us_heap = &g_mmheap, + + /* Task/thread startup routines */ + + .task_startup = nxtask_startup, + + /* Signal handler trampoline */ + + .signal_handler = up_signal_handler, + + /* Userspace work queue support (declared in include/nuttx/wqueue.h) */ + +#ifdef CONFIG_LIBC_USRWORK + .work_usrstart = work_usrstart, +#endif +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#endif /* CONFIG_BUILD_PROTECTED && !__KERNEL__ */ diff --git a/boards/xtensa/esp32/common/scripts/esp32.template.ld b/boards/xtensa/esp32/common/scripts/flat.template.ld similarity index 99% rename from boards/xtensa/esp32/common/scripts/esp32.template.ld rename to boards/xtensa/esp32/common/scripts/flat.template.ld index 36aa1ed6893..826dd21ba07 100644 --- a/boards/xtensa/esp32/common/scripts/esp32.template.ld +++ b/boards/xtensa/esp32/common/scripts/flat.template.ld @@ -1,5 +1,5 @@ /**************************************************************************** - * boards/xtensa/esp32/common/scripts/esp32.template.ld + * boards/xtensa/esp32/common/scripts/flat.template.ld * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with diff --git a/boards/xtensa/esp32/common/scripts/kernel-space.ld b/boards/xtensa/esp32/common/scripts/kernel-space.ld new file mode 100755 index 00000000000..5e0013fd554 --- /dev/null +++ b/boards/xtensa/esp32/common/scripts/kernel-space.ld @@ -0,0 +1,313 @@ +/**************************************************************************** + * boards/xtensa/esp32/common/scripts/kernel-space.ld + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/* Provide these so there is no need for using config files for this */ + +__uirom_start = ORIGIN(UIROM); +__uirom_size = LENGTH(UIROM); +__uirom_end = ORIGIN(UIROM) + LENGTH(UIROM); +__udrom_start = ORIGIN(UDROM); +__udrom_size = LENGTH(UDROM); +__udrom_end = ORIGIN(UDROM) + LENGTH(UDROM); +__uiram_start = ORIGIN(UIRAM); +__uiram_size = LENGTH(UIRAM); +__uiram_end = ORIGIN(UIRAM) + LENGTH(UIRAM); +__udram_start = ORIGIN(UDRAM); +__udram_size = LENGTH(UDRAM); +__udram_end = ORIGIN(UDRAM) + LENGTH(UDRAM); + +/* Provide the kernel boundaries as well */ + +__kirom_start = ORIGIN(KIROM); +__kirom_size = LENGTH(KIROM); +__kdrom_start = ORIGIN(KDROM); +__kdrom_size = LENGTH(KDROM); +__kdrom_start = ORIGIN(KDROM); +__kdrom_size = LENGTH(KDROM); +__kiram_0_start = ORIGIN(KIRAM_0); +__kiram_0_size = LENGTH(KIRAM_0); +__kiram_0_end = ORIGIN(KIRAM_0) + LENGTH(KIRAM_0); +__kiram_1_start = ORIGIN(KIRAM_1); +__kiram_1_size = LENGTH(KIRAM_1); +__kiram_1_end = ORIGIN(KIRAM_1) + LENGTH(KIRAM_1); +__kdram_0_start = ORIGIN(KDRAM_0); +__kdram_0_size = LENGTH(KDRAM_0); +__kdram_0_end = ORIGIN(KDRAM_0) + LENGTH(KDRAM_0); +__kdram_1_start = ORIGIN(KDRAM_1); +__kdram_1_size = LENGTH(KDRAM_1); +__kdram_1_end = ORIGIN(KDRAM_1) + LENGTH(KDRAM_1); + +/* Heap ends at top of dram0_0_seg */ + +_eheap = 0x40000000; + +ENTRY(_stext) + +SECTIONS +{ + /* Send .iram0 code to iram */ + + .iram0.vectors : + { + /* Vectors go to IRAM */ + + _init_start = ABSOLUTE(.); + + __vectors_start = ABSOLUTE(.); + + /* Vectors according to builds/RF-2015.2-win32/esp108_v1_2_s5_512int_2/config.html */ + + . = 0x0; + KEEP (*(.window_vectors.text)); + . = 0x180; + KEEP (*(.xtensa_level2_vector.text)); + . = 0x1c0; + KEEP (*(.xtensa_level3_vector.text)); + . = 0x200; + KEEP (*(.xtensa_level4_vector.text)); + . = 0x240; + KEEP (*(.xtensa_level5_vector.text)); + . = 0x280; + KEEP (*(.debug_exception_vector.text)); + . = 0x2c0; + KEEP (*(.nmi_vector.text)); + . = 0x300; + KEEP (*(.kernel_exception_vector.text)); + . = 0x340; + KEEP (*(.user_exception_vector.text)); + . = 0x3c0; + KEEP (*(.double_exception_vector.text)); + . = 0x400; + *(.*_vector.literal) + + . = ALIGN (16); + + __vectors_end = ABSOLUTE(.); + + *(.entry.text) + *(.init.literal) + *(.init) + + _init_end = ABSOLUTE(.); + } >KIRAM_0 + + .iram0.text : + { + /* Code marked as running out of IRAM */ + + _iram_text_start = ABSOLUTE(.); + *(.iram1 .iram1.*) + *librtc.a:(.literal .text .literal.* .text.*) + *libkarch.a:esp32_spiflash.*(.literal .text .literal.* .text.*) + *libkarch.a:xtensa_cpupause.*(.literal .text .literal.* .text.*) + *libkarch.a:xtensa_copystate.*(.literal .text .literal.* .text.*) + *libkarch.a:xtensa_interruptcontext.*(.literal .text .literal.* .text.*) + *libkarch.a:xtensa_testset.*(.literal .text .literal.* .text.*) + + *libsched.a:sched_suspendscheduler.*(.literal .text .literal.* .text.*) + *libsched.a:sched_note.*(.literal .text .literal.* .text.*) + *libsched.a:sched_thistask.*(.literal .text .literal.* .text.*) + *libsched.a:spinlock.*(.literal .text .literal.* .text.*) + *libsched.a:irq_csection.*(.literal .text .literal.* .text.*) + *libsched.a:irq_dispatch.*(.literal .text .literal.* .text.*) + + *(.wifirxiram .wifirxiram.*) + *(.wifi0iram .wifi0iram.*) + *(.wifislpiram .wifislpiram.*) + *(.wifislprxiram .wifislprxiram.*) + *(.phyiram .phyiram.*) + _iram_text_end = ABSOLUTE(.); + + /* IRAM heap starts at the end of iram0_0_seg */ + + . = ALIGN (4); + _siramheap = ABSOLUTE(.); + } >KIRAM_1 + + /* Shared RAM */ + + .dram0.bss (NOLOAD) : + { + /* .bss initialized on power-up */ + + . = ALIGN (8); + _sbss = ABSOLUTE(.); + _bss_start = ABSOLUTE(.); + *(.ext_ram.bss*) + _bt_bss_start = ABSOLUTE(.); + *libbt.a:(.bss .bss.* COMMON) + . = ALIGN (4); + _bt_bss_end = ABSOLUTE(.); + _btdm_bss_start = ABSOLUTE(.); + *libbtdm_app.a:(.bss .bss.* COMMON) + . = ALIGN (4); + _btdm_bss_end = ABSOLUTE(.); + . = ALIGN (8); + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + *(.dynbss) + KEEP (*(.bss)) + *(.bss.*) + *(.share.mem) + *(.gnu.linkonce.b.*) + *(COMMON) + *libkarch.a:esp32_spiflash.*(.bss .bss.* COMMON) + *libkarch.a:xtensa_cpupause.*(.bss .bss.* COMMON) + *libkarch.a:xtensa_copystate.*(.bss .bss.* COMMON) + *libkarch.a:xtensa_interruptcontext.*(.bss .bss.* COMMON) + *libkarch.a:xtensa_testset.*(.bss .bss.* COMMON) + + *libsched.a:sched_suspendscheduler.*(.bss .bss.* COMMON) + *libsched.a:sched_thistask.*(.bss .bss.* COMMON) + *libsched.a:sched_note.*(.bss .bss.* COMMON) + *libsched.a:spinlock.*(.bss .bss.* COMMON) + *libsched.a:irq_csection.*(.bss .bss.* COMMON) + *libsched.a:irq_dispatch.*(.bss .bss.* COMMON) + + . = ALIGN(8); + _bss_end = ABSOLUTE(.); + _ebss = ABSOLUTE(.); + } >KDRAM_0 + + .noinit (NOLOAD): + { + /* This section contains data that is not initialized during load, + * or during the application's initialization sequence. + */ + + *(.noinit) + } >KDRAM_0 + + .dram0.data : + { + /* .data initialized on power-up in ROMed configurations. */ + + _sdata = ABSOLUTE(.); + _bt_data_start = ABSOLUTE(.); + *libbt.a:(.data .data.*) + . = ALIGN (4); + _bt_data_end = ABSOLUTE(.); + _btdm_data_start = ABSOLUTE(.); + *libbtdm_app.a:(.data .data.*) + . = ALIGN (4); + _btdm_data_end = ABSOLUTE(.); + KEEP (*(.data)) + KEEP (*(.data.*)) + KEEP (*(.gnu.linkonce.d.*)) + KEEP (*(.data1)) + KEEP (*(.sdata)) + KEEP (*(.sdata.*)) + KEEP (*(.gnu.linkonce.s.*)) + KEEP (*(.sdata2)) + KEEP (*(.sdata2.*)) + KEEP (*(.gnu.linkonce.s2.*)) + KEEP (*(.jcr)) + *(.dram1 .dram1.*) + *libphy.a:(.rodata .rodata.*) + *libkarch.a:esp32_spiflash.*(.rodata .rodata.*) + *libkarch.a:xtensa_cpupause.*(.rodata .rodata.*) + *libkarch.a:xtensa_copystate.*(.rodata .rodata.*) + *libkarch.a:xtensa_interruptcontext.*(.rodata .rodata.*) + *libkarch.a:xtensa_testset.*(.rodata .rodata.*) + + *libsched.a:sched_suspendscheduler.*(.rodata .rodata.*) + *libsched.a:sched_thistask.*(.rodata .rodata.*) + *libsched.a:sched_note.*(.rodata .rodata.*) + *libsched.a:spinlock.*(.rodata .rodata.*) + *libsched.a:irq_csection.*(.rodata .rodata.*) + *libsched.a:irq_dispatch.*(.rodata .rodata.*) + + . = ALIGN(4); + _edata = ABSOLUTE(.); + + /* Heap starts at the end of .data */ + + _sheap = ABSOLUTE(.); + } >KDRAM_0 + + .flash.rodata : + { + _srodata = ABSOLUTE(.); + *(.rodata) + *(.rodata.*) + *(.irom1.text) /* catch stray ICACHE_RODATA_ATTR */ + *(.gnu.linkonce.r.*) + *(.rodata1) + __XT_EXCEPTION_TABLE_ = ABSOLUTE(.); + *(.xt_except_table) + *(.gcc_except_table) + *(.gcc_except_table.*) + *(.gnu.linkonce.e.*) + *(.gnu.version_r) + *(.eh_frame) + + . = (. + 3) & ~ 3; + + /* C++ constructor and destructor tables, properly ordered: */ + + _sinit = ABSOLUTE(.); + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + _einit = ABSOLUTE(.); + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + + /* C++ exception handlers table: */ + + __XT_EXCEPTION_DESCS_ = ABSOLUTE(.); + *(.xt_except_desc) + *(.gnu.linkonce.h.*) + __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); + *(.xt_except_desc_end) + *(.dynamic) + *(.gnu.version_d) + _erodata = ABSOLUTE(.); + /* Literals are also RO data. */ + _lit4_start = ABSOLUTE(.); + *(*.lit4) + *(.lit4.*) + *(.gnu.linkonce.lit4.*) + _lit4_end = ABSOLUTE(.); + . = ALIGN(4); + } >KDROM + + .flash.text : + { + _stext = .; + _text_start = ABSOLUTE(.); + *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */ + *(.fini.literal) + *(.fini) + *(.gnu.version) + _text_end = ABSOLUTE(.); + _etext = .; + } >KIROM +} diff --git a/boards/xtensa/esp32/common/scripts/protected.template.ld b/boards/xtensa/esp32/common/scripts/protected.template.ld new file mode 100644 index 00000000000..80ebe214dbc --- /dev/null +++ b/boards/xtensa/esp32/common/scripts/protected.template.ld @@ -0,0 +1,97 @@ +/**************************************************************************** + * boards/xtensa/esp32/common/scripts/protected.template.ld + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * ESP32 Linker Script Memory Layout + * + * This file describes the memory layout (memory blocks) as virtual + * memory addresses. + * + * kernel-space.ld and user-space.ld contain output sections to link compiler + * output into these memory blocks for the Kernel and User images, + * respectively. + * + * NOTE: That this is not the actual linker script but rather a "template" + * for the esp32_out.ld script. This template script is passed through + * the C preprocessor to include selected configuration options. + * + ****************************************************************************/ + +#include + +#include "esp32_aliases.ld" + +MEMORY +{ + + metadata (RX) : org = 0x0, len = 0x18 + ROM (RX) : org = 0x18, len = 0x100000 + + /* Below values assume the flash cache is on, and have the blocks this + * uses subtracted from the length of the various regions. The 'data access + * port' dram/drom regions map to the same iram/irom regions but are + * connected to the data port of the CPU and e.g. allow bytewise access. + */ + + /* Physically located in SRAM0 */ + KIRAM_0 (RWX) : org = 0x40080000, len = 0x2000 + UIRAM (RWX) : org = 0x40082000, len = 0xe000 + KIRAM_1 (RWX) : org = 0x40090000, len = 0x10000 + + /* Flash mapped instruction data. */ + + /* The 0x20 offset for the KIROM region is a convenience for the Kernel + * binary image generation in Espressif Application Image format. + * Flash cache has 64KB pages. The .bin file which is flashed to the chip + * has a 0x18 byte file header, and each segment has a 0x08 byte segment + * header. Setting this offset makes it simple to meet the flash cache MMU's + * constraint that (paddr % 64KB == vaddr % 64KB). + */ + + KIROM (RX) : org = 0x400d0020, len = 0x330000 - 0x20 + UIROM (RX) : org = 0x40400000, len = 0x400000 + + /* Shared data RAM, excluding memory reserved for ROM bss/data/stack. + * Enabling Bluetooth & Trace Memory features in menuconfig will decrease + * the amount of RAM available to the NuttX Kernel. + */ + + /* Physically located in SRAM2 */ + KDRAM_0 (RW) : org = 0x3ffb0000 + CONFIG_ESP32_BT_RESERVE_DRAM, + len = 0x18000 - CONFIG_ESP32_BT_RESERVE_DRAM + UDRAM (RW) : org = 0x3ffc8000, len = 0x18000 + + /* Physically located in SRAM1 */ + KDRAM_1 (RW) : org = 0x3ffe0000, len = 0x20000 + + /* Flash mapped constant data */ + + /* See KIROM region documentation above for the meaning of the 0x20 offset. + * + * The 0x18 offset for the UDROM region is a convenience for the User + * binary image generation following a custom image format, which defines + * a "metadata" output section containing some information that the Kernel + * needs for properly configuring the External Flash MMU when loading the + * User application image. + */ + + KDROM (R) : org = 0x3f400020, len = 0x80000 - 0x20 + UDROM (R) : org = 0x3f480018, len = 0x80000 - 0x18 +} diff --git a/boards/xtensa/esp32/common/scripts/user-space.ld b/boards/xtensa/esp32/common/scripts/user-space.ld new file mode 100755 index 00000000000..4977cc67515 --- /dev/null +++ b/boards/xtensa/esp32/common/scripts/user-space.ld @@ -0,0 +1,217 @@ +/**************************************************************************** + * boards/xtensa/esp32/common/scripts/user-space.ld + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +SECTIONS +{ + .metadata : + { + /* DROM metadata: + * - Destination address (VMA) for DROM region + * - Flash offset (LMA) for start of DROM region + * - Size of DROM region + */ + + LONG(ADDR(.userspace)) + LONG(LOADADDR(.userspace)) + LONG(SIZEOF(.userspace) + SIZEOF(.rodata)) + + /* IROM metadata: + * - Destination address (VMA) for IROM region + * - Flash offset (LMA) for start of IROM region + * - Size of IROM region + */ + + LONG(ADDR(.text)) + LONG(LOADADDR(.text)) + LONG(SIZEOF(.text)) + } >metadata + + /* section info */ + + __ld_uirom_start = ORIGIN(UIROM); + __ld_uirom_size = LENGTH(UIROM); + __ld_uirom_end = ORIGIN(UIROM) + LENGTH(UIROM); + __ld_udrom_start = ORIGIN(UDROM); + __ld_udrom_size = LENGTH(UDROM); + __ld_udrom_end = ORIGIN(UDROM) + LENGTH(UDROM); + __ld_uiram_start = ORIGIN(UIRAM); + __ld_uiram_size = LENGTH(UIRAM); + __ld_uiram_end = ORIGIN(UIRAM) + LENGTH(UIRAM); + __ld_udram_start = ORIGIN(UDRAM); + __ld_udram_size = LENGTH(UDRAM); + __ld_udram_end = ORIGIN(UDRAM) + LENGTH(UDRAM); + + _eronly = LOADADDR(.data); + + .userspace : + { + *(.userspace) + } >UDROM AT>ROM + + /* Output sections for the Userspace image are given standard names, so + * instead of the Espressif-usual ".flash.text" we name it as ".text". + * The motivation is to ease debugging with GDB when loading symbols from + * both Kernel and User images since GDB's "add-symbol-file" command + * expects to find a .text section at the provided offset. + */ + + .rodata : + { + . = ALIGN(4); + _srodata = ABSOLUTE(.); + + *(.rodata) + *(.rodata.*) + + *(.irom1.text) /* catch stray ICACHE_RODATA_ATTR */ + *(.gnu.linkonce.r.*) + *(.rodata1) + __XT_EXCEPTION_TABLE_ = ABSOLUTE(.); + *(.xt_except_table) + *(.gcc_except_table) + *(.gcc_except_table.*) + *(.gnu.linkonce.e.*) + *(.gnu.version_r) + *(.eh_frame) + + . = (. + 3) & ~ 3; + + /* C++ constructor and destructor tables, properly ordered: */ + + _sinit = ABSOLUTE(.); + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + _einit = ABSOLUTE(.); + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + + /* C++ exception handlers table: */ + + __XT_EXCEPTION_DESCS_ = ABSOLUTE(.); + *(.xt_except_desc) + *(.gnu.linkonce.h.*) + __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.); + *(.xt_except_desc_end) + *(.dynamic) + *(.gnu.version_d) + . = ALIGN(4); /* This table MUST be 4-byte aligned */ + + _erodata = ABSOLUTE(.); + + /* Literals are also RO data. */ + _lit4_start = ABSOLUTE(.); + *(*.lit4) + *(.lit4.*) + *(.gnu.linkonce.lit4.*) + _lit4_end = ABSOLUTE(.); + . = ALIGN(4); + } >UDROM AT>ROM + + .iram0.text : + { + _iram_text_start = ABSOLUTE(.); + + *(.iram1) + *(.iram1.*) + + _iram_text_end = ABSOLUTE(.); + } >UIRAM AT>ROM + + /* Shared RAM */ + + .bss (NOLOAD) : + { + /* .bss initialized on power-up */ + + . = ALIGN (8); + _sbss = ABSOLUTE(.); + + *(.dynsbss) + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + *(.scommon) + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + *(.dynbss) + KEEP (*(.bss)) + *(.bss.*) + *(.share.mem) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(8); + + _ebss = ABSOLUTE(.); + } >UDRAM + + .noinit (NOLOAD): + { + /* This section contains data that is not initialized during load, + * or during the application's initialization sequence. + */ + + . = ALIGN(8); + *(.noinit) + *(.noinit.*) + . = ALIGN(8); + } >UDRAM + + .data : + { + _sdata = ABSOLUTE(.); + KEEP (*(.data)) + KEEP (*(.data.*)) + KEEP (*(.gnu.linkonce.d.*)) + KEEP (*(.data1)) + KEEP (*(.sdata)) + KEEP (*(.sdata.*)) + KEEP (*(.gnu.linkonce.s.*)) + KEEP (*(.sdata2)) + KEEP (*(.sdata2.*)) + KEEP (*(.gnu.linkonce.s2.*)) + KEEP (*(.jcr)) + *(.dram1 .dram1.*) + _edata = ABSOLUTE(.); + . = ALIGN(4); + + /* Heap starts at the end of .data */ + + _sheap = ABSOLUTE(.); + } >UDRAM AT>ROM + + .text : ALIGN(0x00010000) + { + _stext = .; + + *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) + *(.irom0.text) /* catch stray ICACHE_RODATA_ATTR */ + *(.fini.literal) + *(.fini) + *(.gnu.version) + . = ALIGN(4); + + _etext = .; + } >UIROM AT>ROM +} diff --git a/boards/xtensa/esp32/esp32-devkitc/configs/knsh/defconfig b/boards/xtensa/esp32/esp32-devkitc/configs/knsh/defconfig new file mode 100644 index 00000000000..e85a601fb0a --- /dev/null +++ b/boards/xtensa/esp32/esp32-devkitc/configs/knsh/defconfig @@ -0,0 +1,62 @@ +# +# This file is autogenerated: PLEASE DO NOT EDIT IT. +# +# You can use "make menuconfig" to make any modifications to the installed .config file. +# You can then do "make savedefconfig" to generate a new defconfig file that includes your +# modifications. +# +# CONFIG_ARCH_LEDS is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +# CONFIG_NSH_CMDPARMS is not set +CONFIG_ARCH="xtensa" +CONFIG_ARCH_BOARD="esp32-devkitc" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32_DEVKITC=y +CONFIG_ARCH_CHIP="esp32" +CONFIG_ARCH_CHIP_ESP32=y +CONFIG_ARCH_CHIP_ESP32WROVER=y +CONFIG_ARCH_INTERRUPTSTACK=2048 +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_USE_MPU=y +CONFIG_ARCH_XTENSA=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILD_PROTECTED=y +CONFIG_BUILTIN=y +CONFIG_DEBUG_ASSERTIONS=y +CONFIG_DEBUG_ERROR=y +CONFIG_DEBUG_FEATURES=y +CONFIG_DEBUG_FULLOPT=y +CONFIG_DEBUG_INFO=y +CONFIG_DEBUG_SYMBOLS=y +CONFIG_DEBUG_WARN=y +CONFIG_ESP32_UART0=y +CONFIG_FS_PROCFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_IDLETHREAD_STACKSIZE=3072 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INTELHEX_BINARY=y +CONFIG_MM_REGIONS=3 +CONFIG_NDEBUG=y +CONFIG_NSH_ARCHINIT=y +CONFIG_NSH_BUILTIN_APPS=y +CONFIG_NSH_FILEIOSIZE=512 +CONFIG_NSH_LINELEN=64 +CONFIG_NSH_READLINE=y +CONFIG_NUTTX_USERSPACE=0x3f480018 +CONFIG_PASS1_BUILDIR="boards/xtensa/esp32/common/kernel" +CONFIG_PREALLOC_TIMERS=4 +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RAW_BINARY=y +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_STACK_COLORATION=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSTEM_NSH=y +CONFIG_TESTING_GETPRIME=y +CONFIG_TESTING_OSTEST=y +CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/boards/xtensa/esp32/esp32-devkitc/include/board_memorymap.h b/boards/xtensa/esp32/esp32-devkitc/include/board_memorymap.h new file mode 100644 index 00000000000..3a78a915d35 --- /dev/null +++ b/boards/xtensa/esp32/esp32-devkitc/include/board_memorymap.h @@ -0,0 +1,128 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-devkitc/include/board_memorymap.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_XTENSA_ESP32_ESP32_DEVKITC_INCLUDE_BOARD_MEMORYMAP_H +#define __BOARDS_XTENSA_ESP32_ESP32_DEVKITC_INCLUDE_BOARD_MEMORYMAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Kernel ROM */ + +#define KIROM_START (uintptr_t)&__kirom_start +#define KIROM_SIZE (uintptr_t)&__kirom_size +#define KDROM_START (uintptr_t)&__kdrom_start +#define KDROM_SIZE (uintptr_t)&__kdrom_size + +/* Kernel RAM */ + +#define KIRAM_0_START (uintptr_t)&__kiram_0_start +#define KIRAM_0_SIZE (uintptr_t)&__kiram_0_size +#define KIRAM_0_END (uintptr_t)&__kiram_0_end +#define KIRAM_1_START (uintptr_t)&__kiram_1_start +#define KIRAM_1_SIZE (uintptr_t)&__kiram_1_size +#define KIRAM_1_END (uintptr_t)&__kiram_1_end +#define KDRAM_0_START (uintptr_t)&__kdram_0_start +#define KDRAM_0_SIZE (uintptr_t)&__kdram_0_size +#define KDRAM_0_END (uintptr_t)&__kdram_0_end +#define KDRAM_1_START (uintptr_t)&__kdram_1_start +#define KDRAM_1_SIZE (uintptr_t)&__kdram_1_size +#define KDRAM_1_END (uintptr_t)&__kdram_1_end + +/* Exception vectors */ + +#define VECTORS_START (uintptr_t)&__vectors_start +#define VECTORS_END (uintptr_t)&__vectors_end + +/* User ROM */ + +#define UIROM_START (uintptr_t)&__uirom_start +#define UIROM_SIZE (uintptr_t)&__uirom_size +#define UIROM_END (uintptr_t)&__uirom_end +#define UDROM_START (uintptr_t)&__udrom_start +#define UDROM_SIZE (uintptr_t)&__udrom_size +#define UDROM_END (uintptr_t)&__udrom_end + +/* User RAM */ + +#define UIRAM_START (uintptr_t)&__uiram_start +#define UIRAM_SIZE (uintptr_t)&__uiram_size +#define UIRAM_END (uintptr_t)&__uiram_end +#define UDRAM_START (uintptr_t)&__udram_start +#define UDRAM_SIZE (uintptr_t)&__udram_size +#define UDRAM_END (uintptr_t)&__udram_end + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Kernel ROM (RX) */ + +extern uintptr_t __kirom_start; +extern uintptr_t __kirom_size; +extern uintptr_t __kdrom_start; +extern uintptr_t __kdrom_size; + +/* Kernel RAM (RW) */ + +extern uintptr_t __kiram_0_start; +extern uintptr_t __kiram_0_size; +extern uintptr_t __kiram_0_end; +extern uintptr_t __kiram_1_start; +extern uintptr_t __kiram_1_size; +extern uintptr_t __kiram_1_end; +extern uintptr_t __kdram_0_start; +extern uintptr_t __kdram_0_size; +extern uintptr_t __kdram_0_end; +extern uintptr_t __kdram_1_start; +extern uintptr_t __kdram_1_size; +extern uintptr_t __kdram_1_end; + +/* Exception vectors */ + +extern uintptr_t __vectors_start; +extern uintptr_t __vectors_end; + +/* User ROM (RX) */ + +extern uintptr_t __uirom_start; +extern uintptr_t __uirom_size; +extern uintptr_t __uirom_end; +extern uintptr_t __udrom_start; +extern uintptr_t __udrom_size; +extern uintptr_t __udrom_end; + +/* User RAM (RW) */ + +extern uintptr_t __uiram_start; +extern uintptr_t __uiram_size; +extern uintptr_t __uiram_end; +extern uintptr_t __udram_start; +extern uintptr_t __udram_size; +extern uintptr_t __udram_end; + +#endif /* __BOARDS_XTENSA_ESP32_ESP32_DEVKITC_INCLUDE_BOARD_MEMORYMAP_H */ diff --git a/boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs b/boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs index 18d8ad02299..9425f18ac67 100644 --- a/boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs +++ b/boards/xtensa/esp32/esp32-devkitc/scripts/Make.defs @@ -34,10 +34,14 @@ ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld),) ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld else - ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) - ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_mcuboot.ld + ifeq ($(CONFIG_BUILD_PROTECTED),y) + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld else - ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld + ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_mcuboot.ld + else + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld + endif endif endif @@ -50,7 +54,11 @@ endif ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld),) LDSCRIPT_TEMPLATE = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld else - LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld + ifeq ($(CONFIG_BUILD_PROTECTED),y) + LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)protected.template.ld + else + LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)flat.template.ld + endif endif ARCHPICFLAGS = -fpic diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/include/board_memorymap.h b/boards/xtensa/esp32/esp32-ethernet-kit/include/board_memorymap.h new file mode 100644 index 00000000000..dbc4f20c064 --- /dev/null +++ b/boards/xtensa/esp32/esp32-ethernet-kit/include/board_memorymap.h @@ -0,0 +1,128 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-ethernet-kit/include/board_memorymap.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_XTENSA_ESP32_ESP32_ETHERNET_KIT_INCLUDE_BOARD_MEMORYMAP_H +#define __BOARDS_XTENSA_ESP32_ESP32_ETHERNET_KIT_INCLUDE_BOARD_MEMORYMAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Kernel ROM */ + +#define KIROM_START (uintptr_t)&__kirom_start +#define KIROM_SIZE (uintptr_t)&__kirom_size +#define KDROM_START (uintptr_t)&__kdrom_start +#define KDROM_SIZE (uintptr_t)&__kdrom_size + +/* Kernel RAM */ + +#define KIRAM_0_START (uintptr_t)&__kiram_0_start +#define KIRAM_0_SIZE (uintptr_t)&__kiram_0_size +#define KIRAM_0_END (uintptr_t)&__kiram_0_end +#define KIRAM_1_START (uintptr_t)&__kiram_1_start +#define KIRAM_1_SIZE (uintptr_t)&__kiram_1_size +#define KIRAM_1_END (uintptr_t)&__kiram_1_end +#define KDRAM_0_START (uintptr_t)&__kdram_0_start +#define KDRAM_0_SIZE (uintptr_t)&__kdram_0_size +#define KDRAM_0_END (uintptr_t)&__kdram_0_end +#define KDRAM_1_START (uintptr_t)&__kdram_1_start +#define KDRAM_1_SIZE (uintptr_t)&__kdram_1_size +#define KDRAM_1_END (uintptr_t)&__kdram_1_end + +/* Exception vectors */ + +#define VECTORS_START (uintptr_t)&__vectors_start +#define VECTORS_END (uintptr_t)&__vectors_end + +/* User ROM */ + +#define UIROM_START (uintptr_t)&__uirom_start +#define UIROM_SIZE (uintptr_t)&__uirom_size +#define UIROM_END (uintptr_t)&__uirom_end +#define UDROM_START (uintptr_t)&__udrom_start +#define UDROM_SIZE (uintptr_t)&__udrom_size +#define UDROM_END (uintptr_t)&__udrom_end + +/* User RAM */ + +#define UIRAM_START (uintptr_t)&__uiram_start +#define UIRAM_SIZE (uintptr_t)&__uiram_size +#define UIRAM_END (uintptr_t)&__uiram_end +#define UDRAM_START (uintptr_t)&__udram_start +#define UDRAM_SIZE (uintptr_t)&__udram_size +#define UDRAM_END (uintptr_t)&__udram_end + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Kernel ROM (RX) */ + +extern uintptr_t __kirom_start; +extern uintptr_t __kirom_size; +extern uintptr_t __kdrom_start; +extern uintptr_t __kdrom_size; + +/* Kernel RAM (RW) */ + +extern uintptr_t __kiram_0_start; +extern uintptr_t __kiram_0_size; +extern uintptr_t __kiram_0_end; +extern uintptr_t __kiram_1_start; +extern uintptr_t __kiram_1_size; +extern uintptr_t __kiram_1_end; +extern uintptr_t __kdram_0_start; +extern uintptr_t __kdram_0_size; +extern uintptr_t __kdram_0_end; +extern uintptr_t __kdram_1_start; +extern uintptr_t __kdram_1_size; +extern uintptr_t __kdram_1_end; + +/* Exception vectors */ + +extern uintptr_t __vectors_start; +extern uintptr_t __vectors_end; + +/* User ROM (RX) */ + +extern uintptr_t __uirom_start; +extern uintptr_t __uirom_size; +extern uintptr_t __uirom_end; +extern uintptr_t __udrom_start; +extern uintptr_t __udrom_size; +extern uintptr_t __udrom_end; + +/* User RAM (RW) */ + +extern uintptr_t __uiram_start; +extern uintptr_t __uiram_size; +extern uintptr_t __uiram_end; +extern uintptr_t __udram_start; +extern uintptr_t __udram_size; +extern uintptr_t __udram_end; + +#endif /* __BOARDS_XTENSA_ESP32_ESP32_ETHERNET_KIT_INCLUDE_BOARD_MEMORYMAP_H */ diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/Make.defs b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/Make.defs index e3af7dac13e..1e3a48629cc 100644 --- a/boards/xtensa/esp32/esp32-ethernet-kit/scripts/Make.defs +++ b/boards/xtensa/esp32/esp32-ethernet-kit/scripts/Make.defs @@ -34,10 +34,14 @@ ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld),) ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld else - ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) - ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_mcuboot.ld + ifeq ($(CONFIG_BUILD_PROTECTED),y) + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld else - ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld + ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_mcuboot.ld + else + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld + endif endif endif @@ -50,7 +54,11 @@ endif ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld),) LDSCRIPT_TEMPLATE = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld else - LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld + ifeq ($(CONFIG_BUILD_PROTECTED),y) + LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)protected.template.ld + else + LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)flat.template.ld + endif endif ARCHPICFLAGS = -fpic diff --git a/boards/xtensa/esp32/esp32-wrover-kit/include/board_memorymap.h b/boards/xtensa/esp32/esp32-wrover-kit/include/board_memorymap.h new file mode 100644 index 00000000000..566dbeb5d7c --- /dev/null +++ b/boards/xtensa/esp32/esp32-wrover-kit/include/board_memorymap.h @@ -0,0 +1,128 @@ +/**************************************************************************** + * boards/xtensa/esp32/esp32-wrover-kit/include/board_memorymap.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_XTENSA_ESP32_ESP32_WROVER_KIT_INCLUDE_BOARD_MEMORYMAP_H +#define __BOARDS_XTENSA_ESP32_ESP32_WROVER_KIT_INCLUDE_BOARD_MEMORYMAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Kernel ROM */ + +#define KIROM_START (uintptr_t)&__kirom_start +#define KIROM_SIZE (uintptr_t)&__kirom_size +#define KDROM_START (uintptr_t)&__kdrom_start +#define KDROM_SIZE (uintptr_t)&__kdrom_size + +/* Kernel RAM */ + +#define KIRAM_0_START (uintptr_t)&__kiram_0_start +#define KIRAM_0_SIZE (uintptr_t)&__kiram_0_size +#define KIRAM_0_END (uintptr_t)&__kiram_0_end +#define KIRAM_1_START (uintptr_t)&__kiram_1_start +#define KIRAM_1_SIZE (uintptr_t)&__kiram_1_size +#define KIRAM_1_END (uintptr_t)&__kiram_1_end +#define KDRAM_0_START (uintptr_t)&__kdram_0_start +#define KDRAM_0_SIZE (uintptr_t)&__kdram_0_size +#define KDRAM_0_END (uintptr_t)&__kdram_0_end +#define KDRAM_1_START (uintptr_t)&__kdram_1_start +#define KDRAM_1_SIZE (uintptr_t)&__kdram_1_size +#define KDRAM_1_END (uintptr_t)&__kdram_1_end + +/* Exception vectors */ + +#define VECTORS_START (uintptr_t)&__vectors_start +#define VECTORS_END (uintptr_t)&__vectors_end + +/* User ROM */ + +#define UIROM_START (uintptr_t)&__uirom_start +#define UIROM_SIZE (uintptr_t)&__uirom_size +#define UIROM_END (uintptr_t)&__uirom_end +#define UDROM_START (uintptr_t)&__udrom_start +#define UDROM_SIZE (uintptr_t)&__udrom_size +#define UDROM_END (uintptr_t)&__udrom_end + +/* User RAM */ + +#define UIRAM_START (uintptr_t)&__uiram_start +#define UIRAM_SIZE (uintptr_t)&__uiram_size +#define UIRAM_END (uintptr_t)&__uiram_end +#define UDRAM_START (uintptr_t)&__udram_start +#define UDRAM_SIZE (uintptr_t)&__udram_size +#define UDRAM_END (uintptr_t)&__udram_end + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Kernel ROM (RX) */ + +extern uintptr_t __kirom_start; +extern uintptr_t __kirom_size; +extern uintptr_t __kdrom_start; +extern uintptr_t __kdrom_size; + +/* Kernel RAM (RW) */ + +extern uintptr_t __kiram_0_start; +extern uintptr_t __kiram_0_size; +extern uintptr_t __kiram_0_end; +extern uintptr_t __kiram_1_start; +extern uintptr_t __kiram_1_size; +extern uintptr_t __kiram_1_end; +extern uintptr_t __kdram_0_start; +extern uintptr_t __kdram_0_size; +extern uintptr_t __kdram_0_end; +extern uintptr_t __kdram_1_start; +extern uintptr_t __kdram_1_size; +extern uintptr_t __kdram_1_end; + +/* Exception vectors */ + +extern uintptr_t __vectors_start; +extern uintptr_t __vectors_end; + +/* User ROM (RX) */ + +extern uintptr_t __uirom_start; +extern uintptr_t __uirom_size; +extern uintptr_t __uirom_end; +extern uintptr_t __udrom_start; +extern uintptr_t __udrom_size; +extern uintptr_t __udrom_end; + +/* User RAM (RW) */ + +extern uintptr_t __uiram_start; +extern uintptr_t __uiram_size; +extern uintptr_t __uiram_end; +extern uintptr_t __udram_start; +extern uintptr_t __udram_size; +extern uintptr_t __udram_end; + +#endif /* __BOARDS_XTENSA_ESP32_ESP32_WROVER_KIT_INCLUDE_BOARD_MEMORYMAP_H */ diff --git a/boards/xtensa/esp32/esp32-wrover-kit/scripts/Make.defs b/boards/xtensa/esp32/esp32-wrover-kit/scripts/Make.defs index ad65da140dc..026f791c230 100644 --- a/boards/xtensa/esp32/esp32-wrover-kit/scripts/Make.defs +++ b/boards/xtensa/esp32/esp32-wrover-kit/scripts/Make.defs @@ -34,10 +34,14 @@ ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld),) ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld else - ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) - ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_mcuboot.ld + ifeq ($(CONFIG_BUILD_PROTECTED),y) + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld else - ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld + ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_mcuboot.ld + else + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld + endif endif endif @@ -50,7 +54,11 @@ endif ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld),) LDSCRIPT_TEMPLATE = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld else - LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld + ifeq ($(CONFIG_BUILD_PROTECTED),y) + LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)protected.template.ld + else + LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)flat.template.ld + endif endif ARCHPICFLAGS = -fpic diff --git a/boards/xtensa/esp32/ttgo_eink5_v2/include/board_memorymap.h b/boards/xtensa/esp32/ttgo_eink5_v2/include/board_memorymap.h new file mode 100644 index 00000000000..bfd74185b73 --- /dev/null +++ b/boards/xtensa/esp32/ttgo_eink5_v2/include/board_memorymap.h @@ -0,0 +1,128 @@ +/**************************************************************************** + * boards/xtensa/esp32/ttgo_eink5_v2/include/board_memorymap.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_XTENSA_ESP32_TTGO_EINK_5_V2_INCLUDE_BOARD_MEMORYMAP_H +#define __BOARDS_XTENSA_ESP32_TTGO_EINK_5_V2_INCLUDE_BOARD_MEMORYMAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Kernel ROM */ + +#define KIROM_START (uintptr_t)&__kirom_start +#define KIROM_SIZE (uintptr_t)&__kirom_size +#define KDROM_START (uintptr_t)&__kdrom_start +#define KDROM_SIZE (uintptr_t)&__kdrom_size + +/* Kernel RAM */ + +#define KIRAM_0_START (uintptr_t)&__kiram_0_start +#define KIRAM_0_SIZE (uintptr_t)&__kiram_0_size +#define KIRAM_0_END (uintptr_t)&__kiram_0_end +#define KIRAM_1_START (uintptr_t)&__kiram_1_start +#define KIRAM_1_SIZE (uintptr_t)&__kiram_1_size +#define KIRAM_1_END (uintptr_t)&__kiram_1_end +#define KDRAM_0_START (uintptr_t)&__kdram_0_start +#define KDRAM_0_SIZE (uintptr_t)&__kdram_0_size +#define KDRAM_0_END (uintptr_t)&__kdram_0_end +#define KDRAM_1_START (uintptr_t)&__kdram_1_start +#define KDRAM_1_SIZE (uintptr_t)&__kdram_1_size +#define KDRAM_1_END (uintptr_t)&__kdram_1_end + +/* Exception vectors */ + +#define VECTORS_START (uintptr_t)&__vectors_start +#define VECTORS_END (uintptr_t)&__vectors_end + +/* User ROM */ + +#define UIROM_START (uintptr_t)&__uirom_start +#define UIROM_SIZE (uintptr_t)&__uirom_size +#define UIROM_END (uintptr_t)&__uirom_end +#define UDROM_START (uintptr_t)&__udrom_start +#define UDROM_SIZE (uintptr_t)&__udrom_size +#define UDROM_END (uintptr_t)&__udrom_end + +/* User RAM */ + +#define UIRAM_START (uintptr_t)&__uiram_start +#define UIRAM_SIZE (uintptr_t)&__uiram_size +#define UIRAM_END (uintptr_t)&__uiram_end +#define UDRAM_START (uintptr_t)&__udram_start +#define UDRAM_SIZE (uintptr_t)&__udram_size +#define UDRAM_END (uintptr_t)&__udram_end + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Kernel ROM (RX) */ + +extern uintptr_t __kirom_start; +extern uintptr_t __kirom_size; +extern uintptr_t __kdrom_start; +extern uintptr_t __kdrom_size; + +/* Kernel RAM (RW) */ + +extern uintptr_t __kiram_0_start; +extern uintptr_t __kiram_0_size; +extern uintptr_t __kiram_0_end; +extern uintptr_t __kiram_1_start; +extern uintptr_t __kiram_1_size; +extern uintptr_t __kiram_1_end; +extern uintptr_t __kdram_0_start; +extern uintptr_t __kdram_0_size; +extern uintptr_t __kdram_0_end; +extern uintptr_t __kdram_1_start; +extern uintptr_t __kdram_1_size; +extern uintptr_t __kdram_1_end; + +/* Exception vectors */ + +extern uintptr_t __vectors_start; +extern uintptr_t __vectors_end; + +/* User ROM (RX) */ + +extern uintptr_t __uirom_start; +extern uintptr_t __uirom_size; +extern uintptr_t __uirom_end; +extern uintptr_t __udrom_start; +extern uintptr_t __udrom_size; +extern uintptr_t __udrom_end; + +/* User RAM (RW) */ + +extern uintptr_t __uiram_start; +extern uintptr_t __uiram_size; +extern uintptr_t __uiram_end; +extern uintptr_t __udram_start; +extern uintptr_t __udram_size; +extern uintptr_t __udram_end; + +#endif /* __BOARDS_XTENSA_ESP32_TTGO_EINK_5_V2_INCLUDE_BOARD_MEMORYMAP_H */ diff --git a/boards/xtensa/esp32/ttgo_eink5_v2/scripts/Make.defs b/boards/xtensa/esp32/ttgo_eink5_v2/scripts/Make.defs index d15706ea6eb..c83fdebbc8a 100644 --- a/boards/xtensa/esp32/ttgo_eink5_v2/scripts/Make.defs +++ b/boards/xtensa/esp32/ttgo_eink5_v2/scripts/Make.defs @@ -34,10 +34,14 @@ ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld),) ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld else - ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) - ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_mcuboot.ld + ifeq ($(CONFIG_BUILD_PROTECTED),y) + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld else - ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld + ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_mcuboot.ld + else + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld + endif endif endif @@ -50,7 +54,11 @@ endif ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld),) LDSCRIPT_TEMPLATE = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld else - LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld + ifeq ($(CONFIG_BUILD_PROTECTED),y) + LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)protected.template.ld + else + LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)flat.template.ld + endif endif ARCHPICFLAGS = -fpic diff --git a/boards/xtensa/esp32/ttgo_lora_esp32/include/board_memorymap.h b/boards/xtensa/esp32/ttgo_lora_esp32/include/board_memorymap.h new file mode 100644 index 00000000000..98b95f772e5 --- /dev/null +++ b/boards/xtensa/esp32/ttgo_lora_esp32/include/board_memorymap.h @@ -0,0 +1,128 @@ +/**************************************************************************** + * boards/xtensa/esp32/ttgo_lora_esp32/include/board_memorymap.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __BOARDS_XTENSA_ESP32_TTGO_LORA_ESP32_INCLUDE_BOARD_MEMORYMAP_H +#define __BOARDS_XTENSA_ESP32_TTGO_LORA_ESP32_INCLUDE_BOARD_MEMORYMAP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Kernel ROM */ + +#define KIROM_START (uintptr_t)&__kirom_start +#define KIROM_SIZE (uintptr_t)&__kirom_size +#define KDROM_START (uintptr_t)&__kdrom_start +#define KDROM_SIZE (uintptr_t)&__kdrom_size + +/* Kernel RAM */ + +#define KIRAM_0_START (uintptr_t)&__kiram_0_start +#define KIRAM_0_SIZE (uintptr_t)&__kiram_0_size +#define KIRAM_0_END (uintptr_t)&__kiram_0_end +#define KIRAM_1_START (uintptr_t)&__kiram_1_start +#define KIRAM_1_SIZE (uintptr_t)&__kiram_1_size +#define KIRAM_1_END (uintptr_t)&__kiram_1_end +#define KDRAM_0_START (uintptr_t)&__kdram_0_start +#define KDRAM_0_SIZE (uintptr_t)&__kdram_0_size +#define KDRAM_0_END (uintptr_t)&__kdram_0_end +#define KDRAM_1_START (uintptr_t)&__kdram_1_start +#define KDRAM_1_SIZE (uintptr_t)&__kdram_1_size +#define KDRAM_1_END (uintptr_t)&__kdram_1_end + +/* Exception vectors */ + +#define VECTORS_START (uintptr_t)&__vectors_start +#define VECTORS_END (uintptr_t)&__vectors_end + +/* User ROM */ + +#define UIROM_START (uintptr_t)&__uirom_start +#define UIROM_SIZE (uintptr_t)&__uirom_size +#define UIROM_END (uintptr_t)&__uirom_end +#define UDROM_START (uintptr_t)&__udrom_start +#define UDROM_SIZE (uintptr_t)&__udrom_size +#define UDROM_END (uintptr_t)&__udrom_end + +/* User RAM */ + +#define UIRAM_START (uintptr_t)&__uiram_start +#define UIRAM_SIZE (uintptr_t)&__uiram_size +#define UIRAM_END (uintptr_t)&__uiram_end +#define UDRAM_START (uintptr_t)&__udram_start +#define UDRAM_SIZE (uintptr_t)&__udram_size +#define UDRAM_END (uintptr_t)&__udram_end + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/* Kernel ROM (RX) */ + +extern uintptr_t __kirom_start; +extern uintptr_t __kirom_size; +extern uintptr_t __kdrom_start; +extern uintptr_t __kdrom_size; + +/* Kernel RAM (RW) */ + +extern uintptr_t __kiram_0_start; +extern uintptr_t __kiram_0_size; +extern uintptr_t __kiram_0_end; +extern uintptr_t __kiram_1_start; +extern uintptr_t __kiram_1_size; +extern uintptr_t __kiram_1_end; +extern uintptr_t __kdram_0_start; +extern uintptr_t __kdram_0_size; +extern uintptr_t __kdram_0_end; +extern uintptr_t __kdram_1_start; +extern uintptr_t __kdram_1_size; +extern uintptr_t __kdram_1_end; + +/* Exception vectors */ + +extern uintptr_t __vectors_start; +extern uintptr_t __vectors_end; + +/* User ROM (RX) */ + +extern uintptr_t __uirom_start; +extern uintptr_t __uirom_size; +extern uintptr_t __uirom_end; +extern uintptr_t __udrom_start; +extern uintptr_t __udrom_size; +extern uintptr_t __udrom_end; + +/* User RAM (RW) */ + +extern uintptr_t __uiram_start; +extern uintptr_t __uiram_size; +extern uintptr_t __uiram_end; +extern uintptr_t __udram_start; +extern uintptr_t __udram_size; +extern uintptr_t __udram_end; + +#endif /* __BOARDS_XTENSA_ESP32_TTGO_LORA_ESP32_INCLUDE_BOARD_MEMORYMAP_H */ diff --git a/boards/xtensa/esp32/ttgo_lora_esp32/scripts/Make.defs b/boards/xtensa/esp32/ttgo_lora_esp32/scripts/Make.defs index cbb40767c18..89fe0afde0b 100644 --- a/boards/xtensa/esp32/ttgo_lora_esp32/scripts/Make.defs +++ b/boards/xtensa/esp32/ttgo_lora_esp32/scripts/Make.defs @@ -34,10 +34,14 @@ ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32_out.ld ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld),) ARCHSCRIPT += $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.ld else - ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) - ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_mcuboot.ld + ifeq ($(CONFIG_BUILD_PROTECTED),y) + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)kernel-space.ld else - ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld + ifeq ($(CONFIG_ESP32_APP_FORMAT_MCUBOOT),y) + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32_mcuboot.ld + else + ARCHSCRIPT += $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.ld + endif endif endif @@ -50,7 +54,11 @@ endif ifneq ($(wildcard $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld),) LDSCRIPT_TEMPLATE = $(BOARD_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld else - LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)esp32.template.ld + ifeq ($(CONFIG_BUILD_PROTECTED),y) + LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)protected.template.ld + else + LDSCRIPT_TEMPLATE = $(BOARD_COMMON_DIR)$(DELIM)scripts$(DELIM)flat.template.ld + endif endif ARCHPICFLAGS = -fpic diff --git a/tools/esp32/Config.mk b/tools/esp32/Config.mk index f1a6ecffc14..fc8b18a71c7 100644 --- a/tools/esp32/Config.mk +++ b/tools/esp32/Config.mk @@ -128,6 +128,10 @@ endif ESPTOOL_BINS += $(FLASH_APP) +ifeq ($(CONFIG_BUILD_PROTECTED),y) + ESPTOOL_BINS += $(CONFIG_ESP32_USER_IMAGE_OFFSET) nuttx_user.bin +endif + # Commands for colored and formatted output RED = \033[1;31m