newlib: ROM library is build with time_t 64bit on esp32c2

This commit is contained in:
morris 2022-06-09 10:40:51 +08:00
parent 44909aff93
commit 6eb450fa87
6 changed files with 38 additions and 14 deletions

View File

@ -194,10 +194,16 @@ else() # Regular app build
rom_linker_script("version")
rom_linker_script("mbedtls")
if(CONFIG_NEWLIB_NANO_FORMAT AND time_t_size EQUAL 4)
# nano formatting functions in ROM are built for 32-bit time_t,
# only link them if the toolchain is also using 32-bit time_t and nano formatting was requested.
rom_linker_script("newlib-nano")
if(time_t_size EQUAL 8)
# The ROM functions listed in this linker script depend on sizeof(time_t).
# Since ROM for ESP32-C2 was compiled for 64-bit time_t, only link these functions
# if the toolchain is also using 64-bit time_t.
rom_linker_script("newlib-time")
if(CONFIG_NEWLIB_NANO_FORMAT)
# nano formatting functions in ROM are also built for 64-bit time_t.
rom_linker_script("newlib-nano")
endif()
endif()
if(CONFIG_HEAP_TLSF_USE_ROM_IMPL)

View File

@ -0,0 +1,16 @@
/*
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
/* These are the newlib functions and the .bss/.data symbols which are related to 'time_t'
or other structures which include 'time_t' (like 'struct stat').
These ROM functions were compiled with sizeof(time_t) == 8.
When compiling with sizeof(time_t) == 4, these functions should be excluded from the build.
*/
asctime = 0x40000638;
asctime_r = 0x4000063c;
_isatty_r = 0x400004b4;
PROVIDE( __smakebuf_r = 0x400005a0 );
PROVIDE( __swhatbuf_r = 0x400005a4 );
PROVIDE( __swsetup_r = 0x400005b0 );

View File

@ -30,7 +30,6 @@ strncmp = 0x400004a4;
strlen = 0x400004a8;
strstr = 0x400004ac;
bzero = 0x400004b0;
_isatty_r = 0x400004b4;
sbrk = 0x400004b8;
isalnum = 0x400004bc;
isalpha = 0x400004c0;
@ -89,11 +88,8 @@ fflush = 0x40000590;
_fflush_r = 0x40000594;
_fwalk = 0x40000598;
_fwalk_reent = 0x4000059c;
__smakebuf_r = 0x400005a0;
__swhatbuf_r = 0x400005a4;
__swbuf_r = 0x400005a8;
__swbuf = 0x400005ac;
__swsetup_r = 0x400005b0;
_strtod_l = 0x400005b4;
_strtod_r = 0x400005b8;
strtod_l = 0x400005bc;
@ -127,8 +123,6 @@ __ratio = 0x40000628;
_mprec_log10 = 0x4000062c;
__copybits = 0x40000630;
__any_on = 0x40000634;
asctime = 0x40000638;
asctime_r = 0x4000063c;
atof = 0x40000640;
atoff = 0x40000644;
_dtoa_r = 0x40000648;

View File

@ -126,17 +126,17 @@ static bool fn_in_rom(void *fn)
TEST_CASE("check if ROM or Flash is used for functions", "[newlib]")
{
#if CONFIG_NEWLIB_NANO_FORMAT && (CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C2)
#if CONFIG_NEWLIB_NANO_FORMAT
TEST_ASSERT(fn_in_rom(vfprintf));
#else
TEST_ASSERT_FALSE(fn_in_rom(vfprintf));
#endif // CONFIG_NEWLIB_NANO_FORMAT && CONFIG_IDF_TARGETx
#endif // CONFIG_NEWLIB_NANO_FORMAT
#if defined(CONFIG_NEWLIB_NANO_FORMAT)
#if CONFIG_NEWLIB_NANO_FORMAT && (CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32H2)
TEST_ASSERT(fn_in_rom(sscanf));
#else
TEST_ASSERT_FALSE(fn_in_rom(sscanf));
#endif // CONFIG_NEWLIB_NANO_FORMAT
#endif // CONFIG_NEWLIB_NANO_FORMAT && CONFIG_IDF_TARGET_x
#if defined(CONFIG_IDF_TARGET_ESP32) && !defined(CONFIG_SPIRAM)
TEST_ASSERT(fn_in_rom(atoi));

View File

@ -450,7 +450,9 @@ static struct timeval get_time(const char *desc, char *buffer)
gettimeofday(&timestamp, NULL);
struct tm* tm_info = localtime(&timestamp.tv_sec);
strftime(buffer, 32, "%c", tm_info);
#if !CONFIG_NEWLIB_NANO_FORMAT
ESP_LOGI("TAG", "%s: %016llX (%s)", desc, timestamp.tv_sec, buffer);
#endif
return timestamp;
}
@ -462,7 +464,9 @@ TEST_CASE("test time_t wide 64 bits", "[newlib]")
struct tm tm = {4, 14, 3, 19, 0, 138, 0, 0, 0};
struct timeval timestamp = { mktime(&tm), 0 };
#if !CONFIG_NEWLIB_NANO_FORMAT
ESP_LOGI("TAG", "timestamp: %016llX", timestamp.tv_sec);
#endif
settimeofday(&timestamp, NULL);
get_time("Set time", buffer);
@ -494,7 +498,9 @@ TEST_CASE("test time functions wide 64 bits", "[newlib]")
localtime_r(&now, &timeinfo);
time_t t = mktime(&timeinfo);
#if !CONFIG_NEWLIB_NANO_FORMAT
ESP_LOGI("TAG", "Test mktime(). Time: %016llX", t);
#endif
TEST_ASSERT_EQUAL(timestamp.tv_sec, t);
// mktime() has error in newlib-3.0.0. It fixed in newlib-3.0.0.20180720
TEST_ASSERT_EQUAL((timestamp.tv_sec >> 32), (t >> 32));

View File

@ -59,6 +59,7 @@ GDB_REGS_INFO_RISCV_ILP32 = [
GDB_REGS_INFO = {
'esp32c3': GDB_REGS_INFO_RISCV_ILP32,
'esp32c2': GDB_REGS_INFO_RISCV_ILP32,
'esp32h2': GDB_REGS_INFO_RISCV_ILP32
}
@ -152,6 +153,7 @@ def parse_idf_riscv_panic_output(panic_text): # type: (str) -> PanicInfo
PANIC_OUTPUT_PARSERS = {
'esp32c3': parse_idf_riscv_panic_output,
'esp32c2': parse_idf_riscv_panic_output,
'esp32h2': parse_idf_riscv_panic_output
}