Skip to content

Commit

Permalink
feat(newlib): add picolibc support
Browse files Browse the repository at this point in the history
  • Loading branch information
Lapshin committed Dec 2, 2024
1 parent 22a3877 commit 888b5f7
Show file tree
Hide file tree
Showing 171 changed files with 8,434 additions and 1,012 deletions.
2 changes: 1 addition & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[codespell]
skip = build,*.yuv,components/fatfs/src/*,alice.txt,*.rgb,components/wpa_supplicant/*,components/esp_wifi/*,*.pem
skip = build,*.yuv,components/fatfs/src/*,alice.txt,*.rgb,components/wpa_supplicant/*,components/esp_wifi/*,*.pem,components/newlib/COPYING.*
ignore-words-list = ser,dout,rsource,fram,inout,shs,ans,aci,unstall,unstalling,hart,wheight,wel,ot,fane,assertIn,registr,oen,parms
write-changes = true
4 changes: 3 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ repos:
# 2 - any file matching *test*/*expected* (for host tests, if possible use this naming pattern always)
# 3 - any directory named 'testdata'
# 4 - protobuf auto-generated files
# 5 - COPYING files
exclude: &whitespace_excludes |
(?x)^(
.+\.(md|rst|map|bin)|
Expand All @@ -23,7 +24,8 @@ repos:
.*.pb-c.h|
.*.pb-c.c|
.*.yuv|
.*.rgb
.*.rgb|
.*COPYING.*
)$
- id: end-of-file-fixer
exclude: *whitespace_excludes
Expand Down
1 change: 1 addition & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -696,3 +696,4 @@ mainmenu "Espressif IoT Development Framework Configuration"
- CONFIG_ESP_WIFI_ENABLE_ROAMING_APP
- CONFIG_USB_HOST_EXT_PORT_SUPPORT_LS
- CONFIG_USB_HOST_EXT_PORT_RESET_ATTEMPTS
- CONFIG_LIBC_PICOLIBC
2 changes: 2 additions & 0 deletions components/bootloader/subproject/main/bootloader_start.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ static int selected_boot_partition(const bootloader_state_t *bs)
return boot_index;
}

#if CONFIG_LIBC_NEWLIB
// Return global reent struct if any newlib functions are linked to bootloader
struct _reent *__getreent(void)
{
return _GLOBAL_REENT;
}
#endif
1 change: 1 addition & 0 deletions components/bt/common/osi/include/osi/hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#define _HASH_MAP_H_

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

struct hash_map_t;
Expand Down
12 changes: 9 additions & 3 deletions components/console/linenoise/linenoise.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@
// On Linux, we don't need __fbufsize (see comments below), and
// __fbufsize not available on MacOS (which is also considered "Linux" target)
#include <stdio_ext.h> // for __fbufsize
#endif
#endif // !CONFIG_IDF_TARGET_LINUX
#include <stddef.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
Expand Down Expand Up @@ -226,10 +227,15 @@ static void flushWrite(void) {
// Performance on Linux is not considered as critical as on chip targets. Additionally,
// MacOS does not have __fbufsize.
#if !CONFIG_IDF_TARGET_LINUX
if (__fbufsize(stdout) > 0) {
#if CONFIG_LIBC_PICOLIBC
if (((struct __file_bufio *)(stdout))->len > 0)
#else // CONFIG_LIBC_PICOLIBC
if (__fbufsize(stdout) > 0)
#endif // CONFIG_LIBC_PICOLIBC
{
fflush(stdout);
}
#endif
#endif // !CONFIG_IDF_TARGET_LINUX
fsync(fileno(stdout));
}

Expand Down
1 change: 1 addition & 0 deletions components/driver/deprecated/mcpwm_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

#include "sdkconfig.h"
#include <sys/lock.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_log.h"
Expand Down
1 change: 1 addition & 0 deletions components/driver/test_apps/twai/main/test_app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "unity.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

// Some resources are lazy allocated in the TWAI driver, the threshold is left for that case
#define TEST_MEMORY_LEAK_THRESHOLD (200)
Expand Down
1 change: 1 addition & 0 deletions components/esp-tls/test_apps/main/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#else
#include "sha/sha_block.h"
#endif
#include "esp_newlib.h"

#if SOC_SHA_SUPPORT_SHA512
#define SHA_TYPE SHA2_512
Expand Down
1 change: 1 addition & 0 deletions components/esp_driver_cam/dvp/src/esp_cam_ctlr_dvp_cam.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <sys/lock.h>
#include <sys/param.h>
#include "hal/gpio_ll.h"
#include "hal/cam_ll.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "unity_test_runner.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

// Some resources are lazy allocated in gpio/rtcio driver, the threshold is left for that case
#define TEST_MEMORY_LEAK_THRESHOLD (100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "unity.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

// Some resources are lazy allocated in the driver, the threshold is left for that case
#define TEST_MEMORY_LEAK_THRESHOLD (300)
Expand Down
1 change: 1 addition & 0 deletions components/esp_driver_gptimer/src/gptimer_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <sys/lock.h>
#include "esp_check.h"
#include "esp_clk_tree.h"
#include "esp_private/esp_clk_tree_common.h"
Expand Down
1 change: 1 addition & 0 deletions components/esp_driver_i2c/i2c_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <sys/lock.h>
#include <string.h>
#include <stdio.h>
#include "sdkconfig.h"
Expand Down
1 change: 1 addition & 0 deletions components/esp_driver_ledc/src/ledc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <sys/lock.h>
#include <sys/param.h>
#include "esp_types.h"
#include "freertos/FreeRTOS.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "unity.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

// Some resources are lazy allocated in LEDC driver, the threshold is left for that case
// This leak is large since LEDC driver does not provide channel delete mechanism
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "unity_test_runner.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

// Some resources are lazy allocated in pulse_cnt driver, the threshold is left for that case
#define TEST_MEMORY_LEAK_THRESHOLD (400)
Expand Down
1 change: 1 addition & 0 deletions components/esp_driver_ppa/src/ppa_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <stdint.h>
#include <sys/queue.h>
#include <sys/lock.h>
#include "sdkconfig.h"
#include "driver/ppa.h"
#include "freertos/FreeRTOS.h"
Expand Down
1 change: 1 addition & 0 deletions components/esp_driver_ppa/test_apps/main/test_app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "unity.h"
#include "unity_test_runner.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"
#include "unity_test_utils.h"

// Some resources are lazy allocated in the driver, the threshold is left for that case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "unity_test_runner.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

// Some resources are lazy allocated in RMT driver, so we reserved this threadhold when checking memory leak
// A better way to check a potential memory leak is running a same case by twice, for the second time, the memory usage delta should be zero
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "unity.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"
#include "sdkconfig.h"

#define TEST_MEMORY_LEAK_THRESHOLD (300)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "unity.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

// iterator to load partition tables in `test spi bus lock, with flash` will lead memory not free
#define TEST_MEMORY_LEAK_THRESHOLD (350)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "unity.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

#define TEST_MEMORY_LEAK_THRESHOLD (200)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "unity.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

#define TEST_MEMORY_LEAK_THRESHOLD (200)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "unity.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

#define TEST_MEMORY_LEAK_THRESHOLD (200)

Expand Down
18 changes: 10 additions & 8 deletions components/esp_driver_uart/src/uart_vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
// Token signifying that no character is available
#define NONE -1

#if CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF
#if CONFIG_LIBC_STDOUT_LINE_ENDING_CRLF
# define DEFAULT_TX_MODE ESP_LINE_ENDINGS_CRLF
#elif CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR
#elif CONFIG_LIBC_STDOUT_LINE_ENDING_CR
# define DEFAULT_TX_MODE ESP_LINE_ENDINGS_CR
#else
# define DEFAULT_TX_MODE ESP_LINE_ENDINGS_LF
#endif

#if CONFIG_NEWLIB_STDIN_LINE_ENDING_CRLF
#if CONFIG_LIBC_STDIN_LINE_ENDING_CRLF
# define DEFAULT_RX_MODE ESP_LINE_ENDINGS_CRLF
#elif CONFIG_NEWLIB_STDIN_LINE_ENDING_CR
#elif CONFIG_LIBC_STDIN_LINE_ENDING_CR
# define DEFAULT_RX_MODE ESP_LINE_ENDINGS_CR
#else
# define DEFAULT_RX_MODE ESP_LINE_ENDINGS_LF
Expand Down Expand Up @@ -226,6 +226,8 @@ static int uart_rx_char_via_driver(int fd)
static ssize_t uart_write(int fd, const void * data, size_t size)
{
assert(fd >= 0 && fd < 3);
tx_func_t tx_func = s_ctx[fd]->tx_func;
esp_line_endings_t tx_mode = s_ctx[fd]->tx_mode;
const char *data_c = (const char *)data;
/* Even though newlib does stream locking on each individual stream, we need
* a dedicated UART lock if two streams (stdout and stderr) point to the
Expand All @@ -234,13 +236,13 @@ static ssize_t uart_write(int fd, const void * data, size_t size)
_lock_acquire_recursive(&s_ctx[fd]->write_lock);
for (size_t i = 0; i < size; i++) {
int c = data_c[i];
if (c == '\n' && s_ctx[fd]->tx_mode != ESP_LINE_ENDINGS_LF) {
s_ctx[fd]->tx_func(fd, '\r');
if (s_ctx[fd]->tx_mode == ESP_LINE_ENDINGS_CR) {
if (c == '\n' && tx_mode != ESP_LINE_ENDINGS_LF) {
tx_func(fd, '\r');
if (tx_mode == ESP_LINE_ENDINGS_CR) {
continue;
}
}
s_ctx[fd]->tx_func(fd, c);
tx_func(fd, c);
}
_lock_release_recursive(&s_ctx[fd]->write_lock);
return size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "unity_test_runner.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

#define TEST_MEMORY_LEAK_THRESHOLD (200)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "unity_test_runner.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

#define TEST_MEMORY_LEAK_THRESHOLD (212)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "unity.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

// Some resources are lazy allocated, the threadhold is left for that case
#define TEST_MEMORY_LEAK_THRESHOLD (500)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,17 @@
// Token signifying that no character is available
#define NONE -1

#if CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF
#if CONFIG_LIBC_STDOUT_LINE_ENDING_CRLF
# define DEFAULT_TX_MODE ESP_LINE_ENDINGS_CRLF
#elif CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR
#elif CONFIG_LIBC_STDOUT_LINE_ENDING_CR
# define DEFAULT_TX_MODE ESP_LINE_ENDINGS_CR
#else
# define DEFAULT_TX_MODE ESP_LINE_ENDINGS_LF
#endif

#if CONFIG_NEWLIB_STDIN_LINE_ENDING_CRLF
#if CONFIG_LIBC_STDIN_LINE_ENDING_CRLF
# define DEFAULT_RX_MODE ESP_LINE_ENDINGS_CRLF
#elif CONFIG_NEWLIB_STDIN_LINE_ENDING_CR
#elif CONFIG_LIBC_STDIN_LINE_ENDING_CR
# define DEFAULT_RX_MODE ESP_LINE_ENDINGS_CR
#else
# define DEFAULT_RX_MODE ESP_LINE_ENDINGS_LF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "unity.h"
#include "unity_test_utils.h"
#include "esp_heap_caps.h"
#include "esp_newlib.h"

// Some resources are lazy allocated, the threadhold is left for that case
#define TEST_MEMORY_LEAK_THRESHOLD (500)
Expand Down
Loading

0 comments on commit 888b5f7

Please sign in to comment.