1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

picolibc: Use most NEWLIB code with picolibc

In most places, picolibc and newlib are the same, so use
the existing newlib code when compiling with picolibc.

Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Keith Packard 2020-07-08 10:38:28 -07:00
parent c5079270c9
commit e215261ced
12 changed files with 40 additions and 40 deletions

View File

@ -127,7 +127,7 @@ void bootloader(void)
/* cpu specific setup of clocks, peripherals */ /* cpu specific setup of clocks, peripherals */
cpu_init(); cpu_init();
#ifdef MODULE_NEWLIB #if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC)
extern void __libc_init_array(void); extern void __libc_init_array(void);
__libc_init_array(); __libc_init_array();
#endif #endif

View File

@ -174,7 +174,7 @@ void reset_handler_default(void)
/* initialize the board (which also initiates CPU initialization) */ /* initialize the board (which also initiates CPU initialization) */
board_init(); board_init();
#if MODULE_NEWLIB #if MODULE_NEWLIB || MODULE_PICOLIBC
/* initialize std-c library (this must be done after board_init) */ /* initialize std-c library (this must be done after board_init) */
extern void __libc_init_array(void); extern void __libc_init_array(void);
__libc_init_array(); __libc_init_array();

View File

@ -240,9 +240,9 @@ static int _cat(int argc, char **argv)
printf("Usage: %s <file>\n", argv[0]); printf("Usage: %s <file>\n", argv[0]);
return 1; return 1;
} }
/* With newlib, low-level syscalls are plugged to RIOT vfs /* With newlib or picolibc, low-level syscalls are plugged to RIOT vfs
* on native, open/read/write/close/... are plugged to RIOT vfs */ * on native, open/read/write/close/... are plugged to RIOT vfs */
#ifdef MODULE_NEWLIB #if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC)
FILE *f = fopen(argv[1], "r"); FILE *f = fopen(argv[1], "r");
if (f == NULL) { if (f == NULL) {
printf("file %s does not exist\n", argv[1]); printf("file %s does not exist\n", argv[1]);
@ -276,7 +276,7 @@ static int _tee(int argc, char **argv)
return 1; return 1;
} }
#ifdef MODULE_NEWLIB #if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC)
FILE *f = fopen(argv[1], "w+"); FILE *f = fopen(argv[1], "w+");
if (f == NULL) { if (f == NULL) {
printf("error while trying to create %s\n", argv[1]); printf("error while trying to create %s\n", argv[1]);

View File

@ -110,7 +110,7 @@ static inline void log_write(unsigned level, const char *format, ...)
va_end(args); va_end(args);
printf(LOG_RESET_ANSI_COLOR_CODE); printf(LOG_RESET_ANSI_COLOR_CODE);
#ifdef MODULE_NEWLIB #if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC)
/* no fflush on msp430 */ /* no fflush on msp430 */
fflush(stdout); fflush(stdout);
#endif #endif

View File

@ -16,7 +16,7 @@
*/ */
#ifndef DOXYGEN #ifndef DOXYGEN
#if defined(CPU_NATIVE) || MODULE_NEWLIB #if defined(CPU_NATIVE) || MODULE_NEWLIB || MODULE_PICOLIBC
/* If building on native or newlib we need to use the system header instead */ /* If building on native or newlib we need to use the system header instead */
#pragma GCC system_header #pragma GCC system_header
/* without the GCC pragma above #include_next will trigger a pedantic error */ /* without the GCC pragma above #include_next will trigger a pedantic error */

View File

@ -72,7 +72,7 @@ void progress_bar_print(char *prefix, char *suffix, uint8_t value)
/* show cursor */ /* show cursor */
printf("\033[?25h"); printf("\033[?25h");
#ifdef MODULE_NEWLIB #if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC)
fflush(stdout); fflush(stdout);
#endif #endif
} }

View File

@ -82,7 +82,7 @@ int _ntpdate(int argc, char **argv)
puts("Error in synchronization"); puts("Error in synchronization");
return 1; return 1;
} }
#ifdef MODULE_NEWLIB #if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC)
struct tm *tm; struct tm *tm;
time_t time = (time_t)(sntp_get_unix_usec() / US_PER_SEC); time_t time = (time_t)(sntp_get_unix_usec() / US_PER_SEC);

View File

@ -42,11 +42,11 @@
#define BS '\x08' /** ASCII "Backspace" */ #define BS '\x08' /** ASCII "Backspace" */
#define DEL '\x7f' /** ASCII "Delete" */ #define DEL '\x7f' /** ASCII "Delete" */
#ifdef MODULE_NEWLIB #if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC)
#define flush_if_needed() fflush(stdout) #define flush_if_needed() fflush(stdout)
#else #else
#define flush_if_needed() #define flush_if_needed()
#endif /* MODULE_NEWLIB */ #endif /* MODULE_NEWLIB || MODULE_PICOLIBC */
#ifndef SHELL_NO_ECHO #ifndef SHELL_NO_ECHO
#define ECHO_ON 1 #define ECHO_ON 1

View File

@ -110,7 +110,7 @@ int main(void)
double false_positive_rate = (double) in / (double) lenA; double false_positive_rate = (double) in / (double) lenA;
/* Use 'fmt/print_float' to work on all platforms (atmega) /* Use 'fmt/print_float' to work on all platforms (atmega)
* Stdout should be flushed before to prevent garbled output. */ * Stdout should be flushed before to prevent garbled output. */
#ifdef MODULE_NEWLIB #if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC)
fflush(stdout); fflush(stdout);
#endif #endif
print_float(false_positive_rate, 6); print_float(false_positive_rate, 6);

View File

@ -325,16 +325,16 @@ static void test_fstat(void)
print_test_result("test_stat__umount", vfs_umount(&_test_vfs_mount) == 0); print_test_result("test_stat__umount", vfs_umount(&_test_vfs_mount) == 0);
} }
#ifdef MODULE_NEWLIB #if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC)
static void test_newlib(void) static void test_libc(void)
{ {
FILE* fl; FILE* fl;
char buf[sizeof(test_txt) + sizeof(test_txt2)]; char buf[sizeof(test_txt) + sizeof(test_txt2)];
print_test_result("test_newlib__mount", vfs_mount(&_test_vfs_mount) == 0); print_test_result("test_libc__mount", vfs_mount(&_test_vfs_mount) == 0);
/* try to open file that doesn't exist */ /* try to open file that doesn't exist */
fl = fopen(FULL_FNAME_NXIST, "r"); fl = fopen(FULL_FNAME_NXIST, "r");
print_test_result("test_newlib__fopen", fl == NULL); print_test_result("test_libc__fopen", fl == NULL);
if (fl) { if (fl) {
fclose(fl); fclose(fl);
} }
@ -342,52 +342,52 @@ static void test_newlib(void)
/* create new file write and check content */ /* create new file write and check content */
remove(FULL_FNAME2); remove(FULL_FNAME2);
fl = fopen(FULL_FNAME2, "w+"); fl = fopen(FULL_FNAME2, "w+");
print_test_result("test_newlib__fopen_w", fl != NULL); print_test_result("test_libc__fopen_w", fl != NULL);
if (fl) { if (fl) {
print_test_result("test_newlib__fputs_w", fputs(test_txt, fl) >= 0); print_test_result("test_libc__fputs_w", fputs(test_txt, fl) >= 0);
rewind(fl); rewind(fl);
print_test_result("test_newlib__fread_w", print_test_result("test_libc__fread_w",
fread(buf, sizeof(*buf), sizeof(buf), fl) > 0); fread(buf, sizeof(*buf), sizeof(buf), fl) > 0);
print_test_result("test_newlib__strcmp_w", strcmp(test_txt, buf) == 0); print_test_result("test_libc__strcmp_w", strcmp(test_txt, buf) == 0);
print_test_result("test_newlib__fclose_w", fclose(fl) == 0); print_test_result("test_libc__fclose_w", fclose(fl) == 0);
} }
/* cppcheck-suppress resourceLeak /* cppcheck-suppress resourceLeak
* (reason: cppcheck <2.0 reports a false positive here) */ * (reason: cppcheck <2.0 reports a false positive here) */
fl = fopen(FULL_FNAME2, "r"); /* open file RO */ fl = fopen(FULL_FNAME2, "r"); /* open file RO */
print_test_result("test_newlib__fopen_r", fl != NULL); print_test_result("test_libc__fopen_r", fl != NULL);
if (fl) { if (fl) {
print_test_result("test_newlib__fclose_r", fclose(fl) == 0); print_test_result("test_libc__fclose_r", fclose(fl) == 0);
} }
/* remove file */ /* remove file */
print_test_result("test_newlib__remove", remove(FULL_FNAME2) == 0); print_test_result("test_libc__remove", remove(FULL_FNAME2) == 0);
/* append to non existing file */ /* append to non existing file */
fl = fopen(FULL_FNAME2, "a"); fl = fopen(FULL_FNAME2, "a");
print_test_result("test_newlib__fopen_a", fl != NULL); print_test_result("test_libc__fopen_a", fl != NULL);
if (fl) { if (fl) {
print_test_result("test_newlib__fputs_a", fputs(test_txt, fl) >= 0); print_test_result("test_libc__fputs_a", fputs(test_txt, fl) >= 0);
print_test_result("test_newlib__fclose_a", fclose(fl) == 0); print_test_result("test_libc__fclose_a", fclose(fl) == 0);
} }
/* append to existing file and check content */ /* append to existing file and check content */
fl = fopen(FULL_FNAME2, "a+"); fl = fopen(FULL_FNAME2, "a+");
print_test_result("test_newlib__fopen_a2", fl != NULL); print_test_result("test_libc__fopen_a2", fl != NULL);
if (fl) { if (fl) {
print_test_result("test_newlib__fputs_a2", fputs(test_txt2, fl) >= 0); print_test_result("test_libc__fputs_a2", fputs(test_txt2, fl) >= 0);
rewind(fl); rewind(fl);
print_test_result("test_newlib__fread_a2", print_test_result("test_libc__fread_a2",
fread(buf, sizeof(*buf), sizeof(buf), fl) > 0); fread(buf, sizeof(*buf), sizeof(buf), fl) > 0);
print_test_result("test_newlib__strcmp_a2", print_test_result("test_libc__strcmp_a2",
strncmp(test_txt, buf, strlen(test_txt)) == 0); strncmp(test_txt, buf, strlen(test_txt)) == 0);
print_test_result("test_newlib__strcmp_a2", strncmp(test_txt2, print_test_result("test_libc__strcmp_a2", strncmp(test_txt2,
&buf[strlen(test_txt)], strlen(test_txt2)) == 0); &buf[strlen(test_txt)], strlen(test_txt2)) == 0);
print_test_result("test_newlib__fclose_a2", fclose(fl) == 0); print_test_result("test_libc__fclose_a2", fclose(fl) == 0);
} }
print_test_result("test_newlib__remove", remove(FULL_FNAME2) == 0); print_test_result("test_libc__remove", remove(FULL_FNAME2) == 0);
print_test_result("test_newlib__umount", vfs_umount(&_test_vfs_mount) == 0); print_test_result("test_libc__umount", vfs_umount(&_test_vfs_mount) == 0);
} }
#endif #endif
@ -421,8 +421,8 @@ int main(void)
test_mkrmdir(); test_mkrmdir();
test_create(); test_create();
test_fstat(); test_fstat();
#ifdef MODULE_NEWLIB #if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC)
test_newlib(); test_libc();
#endif #endif
printf("Test end.\n"); printf("Test end.\n");

View File

@ -389,7 +389,7 @@ void test_entropy(uint32_t samples)
/* Use 'fmt/print_float' to work on all platforms (atmega) /* Use 'fmt/print_float' to work on all platforms (atmega)
* Stdout should be flushed before to prevent garbled output. */ * Stdout should be flushed before to prevent garbled output. */
printf("Calculated "); printf("Calculated ");
#ifdef MODULE_NEWLIB #if defined(MODULE_NEWLIB) || defined(MODULE_PICOLIBC)
/* no fflush on msp430 */ /* no fflush on msp430 */
fflush(stdout); fflush(stdout);
#endif #endif

View File

@ -171,7 +171,7 @@ static void test_vfs_constfs_read_lseek(void)
TEST_ASSERT_EQUAL_INT(0, res); TEST_ASSERT_EQUAL_INT(0, res);
} }
#if MODULE_NEWLIB || defined(BOARD_NATIVE) #if MODULE_NEWLIB || MODULE_PICOLIBC || defined(BOARD_NATIVE)
static void test_vfs_constfs__posix(void) static void test_vfs_constfs__posix(void)
{ {
int res; int res;
@ -210,7 +210,7 @@ Test *tests_vfs_mount_constfs_tests(void)
new_TestFixture(test_vfs_umount__invalid_mount), new_TestFixture(test_vfs_umount__invalid_mount),
new_TestFixture(test_vfs_constfs_open), new_TestFixture(test_vfs_constfs_open),
new_TestFixture(test_vfs_constfs_read_lseek), new_TestFixture(test_vfs_constfs_read_lseek),
#if MODULE_NEWLIB || defined(BOARD_NATIVE) #if MODULE_NEWLIB || MODULE_PICOLIBC || defined(BOARD_NATIVE)
new_TestFixture(test_vfs_constfs__posix), new_TestFixture(test_vfs_constfs__posix),
#endif #endif
}; };