diff --git a/components/esp_rom/CMakeLists.txt b/components/esp_rom/CMakeLists.txt index 82f24b519..55c406a87 100644 --- a/components/esp_rom/CMakeLists.txt +++ b/components/esp_rom/CMakeLists.txt @@ -42,10 +42,13 @@ else() # Regular app build elseif(target STREQUAL "esp32s2") # no SPIRAM workaround for esp32s2 - # no nano formatting function in ROM list(APPEND scripts "esp32s2/ld/esp32s2.rom.newlib-funcs.ld" "esp32s2/ld/esp32s2.rom.spiflash.ld") + + if(CONFIG_NEWLIB_NANO_FORMAT) + list(APPEND scripts "esp32s2/ld/esp32s2.rom.newlib-nano.ld") + endif() endif() target_linker_script(${COMPONENT_LIB} INTERFACE "${scripts}") diff --git a/components/esp_rom/esp32s2/ld/esp32s2.rom.newlib-funcs.ld b/components/esp_rom/esp32s2/ld/esp32s2.rom.newlib-funcs.ld index 4958f2f03..c859f655b 100644 --- a/components/esp_rom/esp32s2/ld/esp32s2.rom.newlib-funcs.ld +++ b/components/esp_rom/esp32s2/ld/esp32s2.rom.newlib-funcs.ld @@ -20,11 +20,6 @@ fclose = 0x4001a804; _fclose_r = 0x4001a714; fflush = 0x40001bb8; _fflush_r = 0x40001b30; -fiprintf = 0x40000a3c; -_fiprintf_r = 0x40000a18; -__fp_lock_all = 0x4001a638; -fprintf = 0x40000a3c; -_fprintf_r = 0x40000a18; __fp_unlock_all = 0x4001a64c; __fputwc = 0x40001770; fputwc = 0x40001864; @@ -76,7 +71,6 @@ __sinit = 0x4001a538; __sinit_lock_acquire = 0x4001a520; __sinit_lock_release = 0x4001a52c; __smakebuf_r = 0x40001954; -__sprint_r = 0x40000aec; srand = 0x40007a24; __sread = 0x4001a660; __sseek = 0x4001a6cc; @@ -116,10 +110,6 @@ __swsetup_r = 0x40001690; toascii = 0x4001af90; tolower = 0x40008158; toupper = 0x40008174; -vfiprintf = 0x40000e40; -_vfiprintf_r = 0x40000b58; -vfprintf = 0x40000e40; -_vfprintf_r = 0x40000b58; wcrtomb = 0x400012f4; _wcrtomb_r = 0x400012a0; _wctomb_r = 0x400018ac; diff --git a/components/esp_rom/esp32s2/ld/esp32s2.rom.newlib-nano.ld b/components/esp_rom/esp32s2/ld/esp32s2.rom.newlib-nano.ld new file mode 100644 index 000000000..260bb723c --- /dev/null +++ b/components/esp_rom/esp32s2/ld/esp32s2.rom.newlib-nano.ld @@ -0,0 +1,26 @@ +/* These are the printf/scanf related newlib functions present in ESP32-S2 ROM. + These functions are compiled with newlib "nano" format option. + As such, they don's support 64-bit integer formats. + Floating point formats are supported by setting _printf_float and + _scanf_float entries in syscall table. This is done automatically + by startup code. + See also esp32s2.rom.newlib-data.ld for the list of .data/.bss symbols + used by newlib functions, and esp32s2.rom.newlib-funcs.ld for the list + of general newlib functions. + + Unlike other ROM functions which are exported using PROVIDE, which declares + weak symbols, newlib related functions are exported using assignment, + which declares strong symbols. This is done so that ROM functions are always + used instead of the ones provided by libc.a. + */ + +fiprintf = 0x40000a3c; +_fiprintf_r = 0x40000a18; +__fp_lock_all = 0x4001a638; +fprintf = 0x40000a3c; +_fprintf_r = 0x40000a18; +__sprint_r = 0x40000aec; +vfiprintf = 0x40000e40; +_vfiprintf_r = 0x40000b58; +vfprintf = 0x40000e40; +_vfprintf_r = 0x40000b58; diff --git a/components/newlib/test/test_newlib.c b/components/newlib/test/test_newlib.c index 4cfec3e40..f0c4216d1 100644 --- a/components/newlib/test/test_newlib.c +++ b/components/newlib/test/test_newlib.c @@ -8,6 +8,7 @@ #include #include "unity.h" #include "sdkconfig.h" +#include "soc/soc.h" TEST_CASE("test ctype functions", "[newlib]") { @@ -19,7 +20,7 @@ TEST_CASE("test ctype functions", "[newlib]") TEST_ASSERT_FALSE( isspace('0') || isspace('9') || isspace(')') || isspace('A') || isspace('*') || isspace('\x81') || isspace('a')); } -TEST_CASE("test atoX functions", "[newlib][ignore]") +TEST_CASE("test atoX functions", "[newlib]") { TEST_ASSERT_EQUAL_INT(-2147483648, atoi("-2147483648")); TEST_ASSERT_EQUAL_INT(2147483647, atoi("2147483647")); @@ -116,29 +117,34 @@ TEST_CASE("test asctime", "[newlib]") TEST_ASSERT_EQUAL_STRING(buf, time_str); } -static bool fn_in_rom(void *fn, const char *name) +static bool fn_in_rom(void *fn) { const int fnaddr = (int)fn; - return (fnaddr >= 0x40000000) && (fnaddr < 0x40070000); + return (fnaddr >= SOC_IROM_MASK_LOW && fnaddr < SOC_IROM_MASK_HIGH); } TEST_CASE("check if ROM or Flash is used for functions", "[newlib]") { -#if defined(CONFIG_NEWLIB_NANO_FORMAT) && !defined(CONFIG_SPIRAM) - TEST_ASSERT(fn_in_rom(printf, "printf")); - TEST_ASSERT(fn_in_rom(sscanf, "sscanf")); +#if defined(CONFIG_NEWLIB_NANO_FORMAT) + TEST_ASSERT(fn_in_rom(vfprintf)); #else - TEST_ASSERT_FALSE(fn_in_rom(printf, "printf")); - TEST_ASSERT_FALSE(fn_in_rom(sscanf, "sscanf")); -#endif -#if !defined(CONFIG_SPIRAM) - TEST_ASSERT(fn_in_rom(atoi, "atoi")); - TEST_ASSERT(fn_in_rom(strtol, "strtol")); + TEST_ASSERT_FALSE(fn_in_rom(vfprintf)); +#endif // CONFIG_NEWLIB_NANO_FORMAT + +#if defined(CONFIG_IDF_TARGET_ESP32) && defined(CONFIG_NEWLIB_NANO_FORMAT) + TEST_ASSERT(fn_in_rom(sscanf)); #else - TEST_ASSERT_FALSE(fn_in_rom(atoi, "atoi")); - TEST_ASSERT_FALSE(fn_in_rom(strtol, "strtol")); -#endif + TEST_ASSERT_FALSE(fn_in_rom(sscanf)); +#endif // CONFIG_IDF_TARGET_ESP32 && CONFIG_NEWLIB_NANO_FORMAT + +#if defined(CONFIG_IDF_TARGET_ESP32) && !defined(CONFIG_SPIRAM) + TEST_ASSERT(fn_in_rom(atoi)); + TEST_ASSERT(fn_in_rom(strtol)); +#else + TEST_ASSERT_FALSE(fn_in_rom(atoi)); + TEST_ASSERT_FALSE(fn_in_rom(strtol)); +#endif // defined(CONFIG_IDF_TARGET_ESP32) && !defined(CONFIG_SPIRAM) } #ifndef CONFIG_NEWLIB_NANO_FORMAT @@ -158,8 +164,8 @@ TEST_CASE("test 64bit int formats", "[newlib]") TEST_ASSERT_EQUAL(1, ret); TEST_ASSERT_EQUAL(val, sval); } -#else -TEST_CASE("test 64bit int formats", "[newlib][ignore]") +#else // CONFIG_NEWLIB_NANO_FORMAT +TEST_CASE("test 64bit int formats", "[newlib]") { char* res = NULL; const uint64_t val = 123456789012LL; @@ -174,7 +180,7 @@ TEST_CASE("test 64bit int formats", "[newlib][ignore]") TEST_ASSERT_EQUAL(0, ret); } -#endif +#endif // CONFIG_NEWLIB_NANO_FORMAT TEST_CASE("fmod and fmodf work as expected", "[newlib]")