mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-03 03:31:41 +03:00
Merge branch 'feature/picolibc_v5.5' into 'release/v5.5'
feat(build): add Picolibc support (v5.5) See merge request espressif/esp-idf!44108
This commit is contained in:
@@ -30,8 +30,7 @@ list(APPEND COMPONENTS bootloader_support efuse esp_security mbedtls)
|
||||
# TEE-specific components
|
||||
list(APPEND COMPONENTS tee_flash_mgr tee_ota_ops tee_sec_storage tee_attestation)
|
||||
|
||||
# Include sdkconfig.h derived from the parent build.
|
||||
include_directories(${CONFIG_DIR})
|
||||
include_directories("${SECURE_SERVICE_HEADERS_DIR}")
|
||||
|
||||
include("${IDF_PATH}/tools/cmake/project.cmake")
|
||||
set(common_req esp_common esp_hw_support esp_rom freertos hal log newlib soc spi_flash)
|
||||
|
||||
@@ -61,7 +61,7 @@ idf_component_register(SRCS ${srcs}
|
||||
|
||||
# NOTE: The ESP32-H2 ROM does not have sprintf/snprintf implementation,
|
||||
# thus newlib-nano implementation from the toolchain has been used.
|
||||
if(CONFIG_IDF_TARGET_ESP32H2)
|
||||
if(CONFIG_LIBC_NEWLIB AND CONFIG_IDF_TARGET_ESP32H2)
|
||||
target_link_libraries(${COMPONENT_LIB} INTERFACE "--specs=nano.specs")
|
||||
endif()
|
||||
|
||||
@@ -76,6 +76,8 @@ target_link_libraries(${COMPONENT_LIB} PRIVATE "-u esp_app_desc_tee_include_impl
|
||||
# Newlib syscalls stub implementation: Linking symbol
|
||||
target_link_libraries(${COMPONENT_LIB} PRIVATE "-u esp_tee_include_syscalls_impl")
|
||||
|
||||
target_link_libraries(${COMPONENT_LIB} PRIVATE "-u esp_tee_include_heap_impl")
|
||||
|
||||
# cut PROJECT_VER and PROJECT_NAME to required 32 characters.
|
||||
idf_build_get_property(project_ver PROJECT_VER)
|
||||
idf_build_get_property(project_name PROJECT_NAME)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_rom_tlsf.h"
|
||||
@@ -151,6 +152,33 @@ void *calloc(size_t n, size_t size)
|
||||
return esp_tee_heap_calloc(n, size);
|
||||
}
|
||||
|
||||
#if CONFIG_LIBC_PICOLIBC
|
||||
void *realloc(void* ptr, size_t size)
|
||||
{
|
||||
if (tee_heap == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ptr == NULL) {
|
||||
return esp_tee_heap_malloc(heap, size);
|
||||
}
|
||||
|
||||
size_t previous_block_size = tlsf_block_size(ptr);
|
||||
void *result = tlsf_realloc(tee_heap->heap_data, ptr, size);
|
||||
if (result) {
|
||||
/* No need to subtract the tlsf_alloc_overhead() as it has already
|
||||
* been subtracted when allocating the block at first with malloc */
|
||||
tee_heap->free_bytes += previous_block_size;
|
||||
tee_heap->free_bytes -= tlsf_block_size(result);
|
||||
if (tee_heap->free_bytes < tee_heap->minimum_free_bytes) {
|
||||
tee_heap->minimum_free_bytes = tee_heap->free_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
void free(void *ptr)
|
||||
{
|
||||
esp_tee_heap_free(ptr);
|
||||
@@ -206,3 +234,10 @@ void *heap_caps_aligned_calloc(size_t alignment, size_t n, size_t size, uint32_t
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* No-op function, used to force linking this file,
|
||||
instead of the heap implementation from libc.
|
||||
*/
|
||||
void esp_tee_include_heap_impl(void)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "esp_random.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#if CONFIG_LIBC_NEWLIB
|
||||
// NOTE: Remove compile-time warnings for the below newlib-provided functions
|
||||
struct _reent *__getreent(void)
|
||||
{
|
||||
@@ -68,6 +70,54 @@ int _getentropy_r(struct _reent *r, void *buffer, size_t length)
|
||||
esp_fill_random(buffer, length);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
int fstat(int fd, struct stat *st)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int close(int fd)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
off_t lseek(int fd, off_t offset, int whence)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t read(int fd, void *ptr, size_t len)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t write(int fd, const void *ptr, size_t len)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int getpid(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int kill(int pid, int sig)
|
||||
{
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int getentropy(void *buffer, size_t length)
|
||||
{
|
||||
esp_fill_random(buffer, length);
|
||||
return 0;
|
||||
}
|
||||
#endif // CONFIG_LIBC_NEWLIB
|
||||
|
||||
void *pthread_getspecific(pthread_key_t key)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user