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

Rationalise compiler flags and esp32 improvements #2388

Merged
merged 5 commits into from
Oct 11, 2021
Merged
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: 0 additions & 5 deletions Sming/Arch/Esp32/Components/driver/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ void notify(smg_uart_t* uart, smg_uart_notify_code_t code)
}
}

__forceinline bool uart_isr_enabled(uint8_t nr)
{
return bitRead(isrMask, nr);
}

/** @brief Determine if the given uart is a real uart or a virtual one
*/
__forceinline bool is_physical(int uart_nr)
Expand Down
39 changes: 16 additions & 23 deletions Sming/Arch/Esp32/Components/esp32/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ SDK_LIBDIRS := \
$(ESP_VARIANT)/ld \
esp_rom/$(ESP_VARIANT)/ld

ESP32_COMPONENT_PATH := $(COMPONENT_PATH)
SDK_DEFAULT_PATH := $(ESP32_COMPONENT_PATH)/sdk

LIBDIRS += \
$(SDK_COMPONENT_LIBDIR) \
$(SDK_BUILD_BASE)/esp-idf/mbedtls/mbedtls/library \
$(SDK_BUILD_BASE)/esp-idf/$(ESP_VARIANT) \
$(SDK_BUILD_BASE)/esp-idf/$(ESP_VARIANT)/ld \
$(COMPONENT_PATH)/ld \
$(ESP32_COMPONENT_PATH)/ld \
$(addprefix $(SDK_COMPONENTS_PATH)/,$(SDK_LIBDIRS))

SDK_INCDIRS := \
Expand Down Expand Up @@ -151,21 +154,14 @@ ifeq ($(ESP_VARIANT),esp32)
SDK_ESP_WIFI_LIBS += rtc
endif

SDK_NEWLIB_LIBS := \
c \
m \
stdc++

ifdef IDF_TARGET_ARCH_RISCV
SDK_TARGET_ARCH_LIBS := hal
else
SDK_TARGET_ARCH_LIBS := hal xt_hal
endif

EXTRA_LIBS := \
gcc \
$(SDK_COMPONENTS) \
$(SDK_NEWLIB_LIBS) \
$(SDK_TARGET_ARCH_LIBS)

ifneq ($(DISABLE_WIFI),1)
Expand Down Expand Up @@ -196,23 +192,18 @@ LDFLAGS_esp32s3 := \
$(call LinkerScript,rom.newlib-data) \
$(call LinkerScript,rom.spiflash)

SDK_WRAP_SYMBOLS :=
SDK_UNDEF_SYMBOLS :=

$(foreach c,$(wildcard $(SDK_DEFAULT_PATH)/*.mk),$(eval include $c))

EXTRA_LDFLAGS := \
-u esp_app_desc \
-u __cxa_guard_dummy -u __cxx_fatal_exception \
-T $(ESP_VARIANT)_out.ld \
-u ld_include_panic_highint_hdl \
$(call LinkerScript,project) \
$(call LinkerScript,peripherals) \
$(call LinkerScript,rom) \
$(call LinkerScript,rom.api) \
$(call LinkerScript,rom.libgcc) \
-u newlib_include_locks_impl \
-u newlib_include_heap_impl \
-u newlib_include_syscalls_impl \
-u pthread_include_pthread_impl \
-u pthread_include_pthread_cond_impl \
-u pthread_include_pthread_local_storage_impl \
-Wl,--undefined=uxTopUsedPriority \
$(call Wrap,\
esp_event_loop_create_default \
esp_event_handler_register \
Expand All @@ -221,10 +212,12 @@ EXTRA_LDFLAGS := \
esp_event_handler_instance_unregister \
esp_event_post \
esp_event_isr_post) \
$(LDFLAGS_$(ESP_VARIANT))
$(LDFLAGS_$(ESP_VARIANT)) \
$(call Undef,$(SDK_UNDEF_SYMBOLS)) \
$(call Wrap,$(SDK_WRAP_SYMBOLS))


SDK_DEFAULT_PATH := $(COMPONENT_PATH)/sdk
SDK_PROJECT_PATH := $(COMPONENT_PATH)/project/$(ESP_VARIANT)/$(BUILD_TYPE)
SDK_PROJECT_PATH := $(ESP32_COMPONENT_PATH)/project/$(ESP_VARIANT)/$(BUILD_TYPE)
SDK_CONFIG_DEFAULTS := $(SDK_PROJECT_PATH)/sdkconfig.defaults

SDKCONFIG_MAKEFILE := $(SDK_PROJECT_PATH)/sdkconfig
Expand Down Expand Up @@ -253,7 +246,7 @@ CUSTOM_TARGETS += checksdk
.PHONY: checksdk
checksdk: $(SDK_PROJECT_PATH) $(SDKCONFIG_H) $(SDKCONFIG_MAKEFILE)
$(Q) $(NINJA) -C $(SDK_BUILD_BASE) bootloader app
$(Q) $(MAKE) --no-print-directory -C $(SDK_DEFAULT_PATH) -f misc.mk copylibs
$(Q) $(MAKE) --no-print-directory -C $(ESP32_COMPONENT_PATH) -f misc.mk copylibs

$(SDKCONFIG_H) $(SDKCONFIG_MAKEFILE) $(SDK_COMPONENT_LIBS): $(SDK_PROJECT_PATH) $(SDK_CONFIG_DEFAULTS) | $(SDK_BUILD_BASE) $(SDK_COMPONENT_LIBDIR)
$(Q) $(SDK_BUILD) reconfigure
Expand Down Expand Up @@ -312,4 +305,4 @@ sdk: ##Pass options to IDF builder, e.g. `make sdk -- --help` or `make sdk menuc

.PHONY: checkdirs
checkdirs: | checksdk

7 changes: 7 additions & 0 deletions Sming/Arch/Esp32/Components/esp32/sdk/app_update.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# app_update
#

# esp_app_desc structure is added as an undefined symbol because otherwise the
# linker will ignore this structure as it has no other files depending on it.
SDK_UNDEF_SYMBOLS += esp_app_desc
57 changes: 57 additions & 0 deletions Sming/Arch/Esp32/Components/esp32/sdk/cxx.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#
# cxx
#

ifndef CONFIG_COMPILER_CXX_EXCEPTIONS
# If exceptions are disabled, ensure our fatal exception
# hooks are preferentially linked over libstdc++ which
# has full exception support
SDK_WRAP_SYMBOLS += \
_Unwind_SetEnableExceptionFdeSorting \
__register_frame_info_bases \
__register_frame_info \
__register_frame \
__register_frame_info_table_bases \
__register_frame_info_table \
__register_frame_table \
__deregister_frame_info_bases \
__deregister_frame_info \
_Unwind_Find_FDE \
_Unwind_GetGR \
_Unwind_GetCFA \
_Unwind_GetIP \
_Unwind_GetIPInfo \
_Unwind_GetRegionStart \
_Unwind_GetDataRelBase \
_Unwind_GetTextRelBase \
_Unwind_SetIP \
_Unwind_SetGR \
_Unwind_GetLanguageSpecificData \
_Unwind_FindEnclosingFunction \
_Unwind_Resume \
_Unwind_RaiseException \
_Unwind_DeleteException \
_Unwind_ForcedUnwind \
_Unwind_Resume_or_Rethrow \
_Unwind_Backtrace \
__cxa_call_unexpected \
__gxx_personality_v0

SDK_UNDEF_SYMBOLS += __cxx_fatal_exception
endif

SDK_UNDEF_SYMBOLS += __cxa_guard_dummy

# Force libpthread to appear later than libstdc++ in link line since libstdc++ depends on libpthread.
# Furthermore, force libcxx to appear later than libgcc because some libgcc unwind code is wrapped, if C++
# exceptions are disabled. libcxx (this component) provides the unwind code wrappers.
# This is to prevent linking of libgcc's unwind code which considerably increases the binary size.

# idf_component_get_property(pthread pthread COMPONENT_LIB)
# idf_component_get_property(cxx cxx COMPONENT_LIB)
# add_library(stdcpp_pthread INTERFACE)
# target_link_libraries(stdcpp_pthread INTERFACE stdc++ $<TARGET_FILE:${pthread}>)
# target_link_libraries(${COMPONENT_LIB} PUBLIC stdcpp_pthread)
# add_library(libgcc_cxx INTERFACE)
# target_link_libraries(libgcc_cxx INTERFACE gcc $<TARGET_FILE:${cxx}>)
# target_link_libraries(${COMPONENT_LIB} PUBLIC libgcc_cxx)
5 changes: 5 additions & 0 deletions Sming/Arch/Esp32/Components/esp32/sdk/esp32.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# esp32
#

SDK_UNDEF_SYMBOLS += call_user_start_cpu0
6 changes: 6 additions & 0 deletions Sming/Arch/Esp32/Components/esp32/sdk/esp_rom.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# esp_rom
#
ifdef CONFIG_IDF_TARGET_ARCH_XTENSA
SDK_WRAP_SYMBOLS += longjmp
endif
18 changes: 18 additions & 0 deletions Sming/Arch/Esp32/Components/esp32/sdk/esp_system.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# esp_system
#

# After system initialization, `start_app` (and its other cores variant) is called.
# This is provided by the user or from another component. Since we can't establish
# dependency on what we don't know, force linker to not drop the symbol regardless
# of link line order.
SDK_UNDEF_SYMBOLS += start_app

ifndef CONFIG_ESP_SYSTEM_SINGLE_CORE_MODE
SDK_UNDEF_SYMBOLS += start_app_other_cores
endif

# ld_include_panic_highint_hdl is added as an undefined symbol because otherwise the
# linker will ignore panic_highint_hdl.S as it has no other files depending on any
# symbols in it.
SDK_UNDEF_SYMBOLS += ld_include_panic_highint_hdl
7 changes: 7 additions & 0 deletions Sming/Arch/Esp32/Components/esp32/sdk/freertos.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# freertos
#

ifdef CONFIG_FREERTOS_DEBUG_OCDAWARE
EXTRA_LDFLAGS += -Wl,--undefined=uxTopUsedPriority
endif
16 changes: 16 additions & 0 deletions Sming/Arch/Esp32/Components/esp32/sdk/heap.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
# heap
#

ifdef CONFIG_HEAP_TRACING
SDK_WRAP_SYMBOLS += \
calloc \
malloc \
free \
realloc \
heap_caps_malloc \
heap_caps_free \
heap_caps_realloc \
heap_caps_malloc_default \
heap_caps_realloc_default
endif
13 changes: 13 additions & 0 deletions Sming/Arch/Esp32/Components/esp32/sdk/newlib.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# newlib
#

# Forces the linker to include heap, syscall, pthread and retargetable locks from this component,
# instead of the implementations provided by newlib.
SDK_UNDEF_SYMBOLS += \
newlib_include_heap_impl \
newlib_include_syscalls_impl \
newlib_include_pthread_impl

# Must link before standard C library
LIBS := newlib $(LIBS)
11 changes: 11 additions & 0 deletions Sming/Arch/Esp32/Components/esp32/sdk/pthread.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# pthread
#
SDK_UNDEF_SYMBOLS += \
pthread_include_pthread_impl \
pthread_include_pthread_cond_impl \
pthread_include_pthread_local_storage_impl

ifdef CONFIG_FREERTOS_ENABLE_STATIC_TASK_CLEAN_UP
SDK_WRAP_SYMBOLS += vPortCleanUpTCB
endif
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

#pragma once

// ==== taken from ESP8266/ets_sys.h
#define ETS_GPIO_INUM 4

// ====

// Default types
#include <limits.h>
#include <assert.h>
Expand All @@ -38,7 +33,7 @@
#include <debug_progmem.h>
#include <stringutil.h>

#define __ESP32_EX__ // System definition ESP8266 SOC
#define __ESP32_EX__ // System definition ESP32 SOC

#define LOCAL static

Expand Down
19 changes: 18 additions & 1 deletion Sming/Arch/Esp32/Components/libc/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,21 @@ COMPONENT_INCDIRS := src/include

COMPONENT_DOXYGEN_INPUT := src/include/sys

EXTRA_LDFLAGS := $(call Wrap,_write_r _read_r)
LIBC_WRAPSYMS := \
_write_r \
_read_r \
putchar \
puts \
vprintf \
printf \
vsnprintf \
vsprintf \
sprintf

EXTRA_LDFLAGS := $(call Wrap,$(LIBC_WRAPSYMS))

EXTRA_LIBS := \
c \
m \
gcc \
stdc++
61 changes: 59 additions & 2 deletions Sming/Arch/Esp32/Components/libc/src/replacements.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
#include <unistd.h>
#include <errno.h>

ssize_t __wrap__write_r(struct _reent* r, int fd, const void* data, size_t size)
#define BUFMAX 16384
#define WRAP(x) __wrap_##x

ssize_t WRAP(_write_r)(struct _reent* r, int fd, const void* data, size_t size)
{
(void)r;
(void)fd; // Ignore, direct everything
return m_nputs(data, size);
}

ssize_t __wrap__read_r(struct _reent* r, int fd, void* dst, size_t size)
ssize_t WRAP(_read_r)(struct _reent* r, int fd, void* dst, size_t size)
{
(void)r;
(void)fd;
Expand All @@ -22,3 +25,57 @@ ssize_t __wrap__read_r(struct _reent* r, int fd, void* dst, size_t size)
errno = ENOSYS;
return -1;
}

size_t WRAP(putc)(char c)
{
return m_putc(c);
}

size_t WRAP(puts)(const char* str)
{
return m_puts(str);
}

int WRAP(vprintf)(const char* format, va_list arg)
{
return m_vprintf(format, arg);
}

int WRAP(printf)(char const* fmt, ...)
{
va_list args;
va_start(args, fmt);
int n = m_vprintf(fmt, args);
va_end(args);
return n;
}

int WRAP(vsnprintf)(char* buf, size_t maxLen, const char* fmt, va_list args)
{
return m_vsnprintf(buf, maxLen, fmt, args);
}

int WRAP(snprintf)(char* buf, int length, const char* fmt, ...)
{
va_list args;

va_start(args, fmt);
int n = m_vsnprintf(buf, length, fmt, args);
va_end(args);

return n;
}

int WRAP(vsprintf)(char* buf, const char* fmt, va_list args)
{
return m_vsnprintf(buf, BUFMAX, fmt, args);
}

int WRAP(sprintf)(char* buf, const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
int n = m_vsnprintf(buf, BUFMAX, fmt, args);
va_end(args);
return n;
}
2 changes: 1 addition & 1 deletion Sming/Arch/Esp32/Components/spi_flash/flashmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ uint32_t flashmem_read(void* to, uint32_t fromaddr, uint32_t size)

bool flashmem_erase_sector(uint32_t sector_id)
{
debug_e("flashmem_erase_sector(0x%08x)", sector_id);
debug_d("flashmem_erase_sector(0x%08x)", sector_id);

return spi_flash_erase_sector(sector_id) == SPI_FLASH_RESULT_OK;
}
Expand Down
Loading