[realtek-ambz] Update stdlib compatibility
This commit is contained in:
@@ -45,6 +45,30 @@ queue.AppendPublic(
|
||||
"-Wl,-wrap,aes_80211_encrypt",
|
||||
"-Wl,-wrap,aes_80211_decrypt",
|
||||
"-Wl,-wrap,DecGTK",
|
||||
# ROM stdlib (wraps/stdlib.c)
|
||||
# stock SDK defines these as macros
|
||||
"-Wl,-wrap,atoi",
|
||||
"-Wl,-wrap,atol",
|
||||
"-Wl,-wrap,strtol",
|
||||
"-Wl,-wrap,strtoul",
|
||||
"-Wl,-wrap,rand",
|
||||
"-Wl,-wrap,strcat",
|
||||
"-Wl,-wrap,strcpy",
|
||||
"-Wl,-wrap,strncat",
|
||||
"-Wl,-wrap,strncpy",
|
||||
"-Wl,-wrap,strchr",
|
||||
"-Wl,-wrap,strcmp",
|
||||
"-Wl,-wrap,strlen",
|
||||
"-Wl,-wrap,strncmp",
|
||||
"-Wl,-wrap,strpbrk",
|
||||
"-Wl,-wrap,strstr",
|
||||
"-Wl,-wrap,strtok",
|
||||
"-Wl,-wrap,memchr",
|
||||
"-Wl,-wrap,memcmp",
|
||||
"-Wl,-wrap,memcpy",
|
||||
"-Wl,-wrap,memmove",
|
||||
"-Wl,-wrap,memset",
|
||||
"-Wl,-wrap,strsep",
|
||||
# stdio wrappers (base/port/printf.c)
|
||||
"-Wl,-wrap,rtl_printf",
|
||||
"-Wl,-wrap,rtl_sprintf",
|
||||
@@ -195,9 +219,8 @@ queue.AddLibrary(
|
||||
srcs=[
|
||||
# mbedTLS from SDK
|
||||
"+<component/common/network/ssl/mbedtls-2.4.0/library/*.c>",
|
||||
# replace these with fixups
|
||||
# replace this with a fixup
|
||||
"-<component/common/network/ssl/mbedtls-2.4.0/library/net_sockets.c>",
|
||||
"-<component/common/network/ssl/mbedtls-2.4.0/library/ssl_tls.c>",
|
||||
],
|
||||
includes=[
|
||||
"+<component/common/network/ssl/mbedtls-2.4.0/include>",
|
||||
|
||||
@@ -6,31 +6,18 @@
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
// va_list is declared by SDK and conflicting
|
||||
#include <stdarg.h>
|
||||
// note: this is *not* replacing any stdlib functions :)
|
||||
#include <platform_stdlib.h>
|
||||
|
||||
// disable typedef in basic_types.h
|
||||
#define boolean boolean_rtl
|
||||
// fix conflicts with Arduino's PinMode enum
|
||||
#define PinMode PinModeRTL
|
||||
// remove log_printf() if included before sdk_private.h
|
||||
#undef log_printf
|
||||
|
||||
#include <strproc.h> // define string macros first
|
||||
#undef isdigit // then remove them, as they conflict
|
||||
#undef islower // with ctype.h macros
|
||||
#undef isprint
|
||||
#undef isspace
|
||||
#undef isxdigit
|
||||
#undef strtol
|
||||
#undef strtoul
|
||||
|
||||
#if LT_RTL8710B
|
||||
#include <ameba_soc.h>
|
||||
#include <rand.h>
|
||||
#include <rt_lib_rom.h>
|
||||
#include <rtl8710b.h>
|
||||
#include <rtl_lib.h>
|
||||
#endif
|
||||
#if LT_RTL8720C
|
||||
#include <rtl8710c.h>
|
||||
@@ -56,7 +43,6 @@ extern "C" {
|
||||
#include <wdt_api.h>
|
||||
|
||||
// remove previously defined workarounds
|
||||
#undef boolean
|
||||
#undef PinMode
|
||||
|
||||
// undefine ROM stdio in favor of printf() library (wrappers)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2023-03-02. */
|
||||
|
||||
// fix conflicting declaration with ArduinoCore-API
|
||||
#ifdef ARDUINO
|
||||
#define boolean boolean_rtl
|
||||
#endif
|
||||
#include_next "basic_types.h"
|
||||
#undef boolean
|
||||
|
||||
12
cores/realtek-ambz/base/fixups/hal_crypto.h
Normal file
12
cores/realtek-ambz/base/fixups/hal_crypto.h
Normal file
@@ -0,0 +1,12 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2023-03-14. */
|
||||
|
||||
#include_next "hal_crypto.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
// mbedTLS (ssl_tls.c) uses S1 and S2 as variable name
|
||||
// rtl8710b_pinmux.h defines them as integer values
|
||||
#if defined(CONFIG_SSL_RSA) && defined(RTL_HW_CRYPTO) && defined(S1)
|
||||
#undef S1
|
||||
#undef S2
|
||||
#endif
|
||||
9
cores/realtek-ambz/base/fixups/memproc.h
Normal file
9
cores/realtek-ambz/base/fixups/memproc.h
Normal file
@@ -0,0 +1,9 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2023-03-14. */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define _memcmp memcmp
|
||||
#define _memcpy memcpy
|
||||
#define _memset memset
|
||||
@@ -0,0 +1,3 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2023-03-14. */
|
||||
|
||||
#include "../platform_stdlib.h"
|
||||
22
cores/realtek-ambz/base/fixups/platform_stdlib.h
Normal file
22
cores/realtek-ambz/base/fixups/platform_stdlib.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2023-03-14. */
|
||||
|
||||
#pragma once
|
||||
|
||||
// platform_stdlib.h in amb1_sdk includes some stdlib headers,
|
||||
// as well as Realtek's stdlib replacement headers. It also defines
|
||||
// some macros to map stdlib functions to SDK functions, so it's
|
||||
// generally just not needed at all.
|
||||
|
||||
// This is also the only file that publicly includes strproc.h and memproc.h,
|
||||
// so this fixup resolves all these issues.
|
||||
|
||||
#include <stdarg.h> /* va_list */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "basic_types.h" // fixup: replaces typedef boolean for Arduino compatibility
|
||||
#include "memproc.h" // fixup: redirects to stdlib
|
||||
#include "strproc.h" // fixup: redirects to stdlib
|
||||
|
||||
#include "diag.h"
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,22 +1,8 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2022-11-26. */
|
||||
/* Copyright (c) Kuba Szczodrzyński 2023-03-14. */
|
||||
|
||||
// make <strproc.h> not #define isprint, isdigit, isxdigit, islower and isspace
|
||||
// this conflicts with stdlib <ctype.h>, if <strproc.h> is included before it
|
||||
#pragma once
|
||||
|
||||
// include <ctype.h> before to get all its macros
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
// make 'static inline int _tolower' unused
|
||||
#undef _tolower
|
||||
#define _tolower _tolower_dummy
|
||||
|
||||
#include_next <strproc.h>
|
||||
|
||||
// restore _tolower to ctype's macro
|
||||
#undef _tolower
|
||||
#define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a')
|
||||
|
||||
// dirty fix for compiling mbedTLS which uses _B as variable name
|
||||
#ifdef CONFIG_SSL_RSA
|
||||
#undef _B
|
||||
#endif
|
||||
#define _strcpy strcpy
|
||||
#define _strlen strlen
|
||||
|
||||
115
cores/realtek-ambz/base/wraps/stdlib.c
Normal file
115
cores/realtek-ambz/base/wraps/stdlib.c
Normal file
@@ -0,0 +1,115 @@
|
||||
/* Copyright (c) Kuba Szczodrzyński 2023-03-14. */
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define ROM __attribute__((long_call))
|
||||
|
||||
ROM int prvAtoi(const char *str);
|
||||
ROM long simple_strtol(const char *str, char **str_end, int base);
|
||||
ROM unsigned long simple_strtoul(const char *str, char **str_end, int base);
|
||||
ROM int Rand();
|
||||
ROM char *__rtl_strcat_v1_00(char *dest, const char *src);
|
||||
ROM char *_strcpy(char *dest, const char *src);
|
||||
ROM char *__rtl_strncat_v1_00(char *dest, const char *src, size_t count);
|
||||
ROM char *_strncpy(char *dest, const char *src, size_t count);
|
||||
ROM char *_strchr(const char *str, int ch);
|
||||
ROM int prvStrCmp(const char *lhs, const char *rhs);
|
||||
ROM size_t prvStrLen(const char *str);
|
||||
ROM int _strncmp(const char *lhs, const char *rhs, size_t count);
|
||||
ROM char *_strpbrk(const char *dest, const char *breakset);
|
||||
ROM char *prvStrStr(const char *str, const char *substr);
|
||||
ROM char *prvStrtok(char *str, const char *delim);
|
||||
ROM void *__rtl_memchr_v1_00(const void *ptr, int ch, size_t count);
|
||||
ROM int _memcmp(const void *lhs, const void *rhs, size_t count);
|
||||
ROM void *_memcpy(void *dest, const void *src, size_t count);
|
||||
ROM void *__rtl_memmove_v1_00(void *dest, const void *src, size_t count);
|
||||
ROM void *_memset(void *dest, int ch, size_t count);
|
||||
ROM char *_strsep(char **stringp, const char *delim);
|
||||
|
||||
int __wrap_atoi(const char *str) {
|
||||
return prvAtoi(str);
|
||||
}
|
||||
|
||||
long __wrap_atol(const char *str) {
|
||||
return simple_strtol(str, NULL, 10);
|
||||
}
|
||||
|
||||
long __wrap_strtol(const char *str, char **str_end, int base) {
|
||||
return simple_strtol(str, str_end, base);
|
||||
}
|
||||
|
||||
unsigned long __wrap_strtoul(const char *str, char **str_end, int base) {
|
||||
return simple_strtoul(str, str_end, base);
|
||||
}
|
||||
|
||||
int __wrap_rand() {
|
||||
return Rand();
|
||||
}
|
||||
|
||||
char *__wrap_strcat(char *dest, const char *src) {
|
||||
return __rtl_strcat_v1_00(dest, src);
|
||||
}
|
||||
|
||||
char *__wrap_strcpy(char *dest, const char *src) {
|
||||
return _strcpy(dest, src);
|
||||
}
|
||||
|
||||
char *__wrap_strncat(char *dest, const char *src, size_t count) {
|
||||
return __rtl_strncat_v1_00(dest, src, count);
|
||||
}
|
||||
|
||||
char *__wrap_strncpy(char *dest, const char *src, size_t count) {
|
||||
return _strncpy(dest, src, count);
|
||||
}
|
||||
|
||||
char *__wrap_strchr(const char *str, int ch) {
|
||||
return _strchr(str, ch);
|
||||
}
|
||||
|
||||
int __wrap_strcmp(const char *lhs, const char *rhs) {
|
||||
return prvStrCmp(lhs, rhs);
|
||||
}
|
||||
|
||||
size_t __wrap_strlen(const char *str) {
|
||||
return prvStrLen(str);
|
||||
}
|
||||
|
||||
int __wrap_strncmp(const char *lhs, const char *rhs, size_t count) {
|
||||
return _strncmp(lhs, rhs, count);
|
||||
}
|
||||
|
||||
char *__wrap_strpbrk(const char *dest, const char *breakset) {
|
||||
return _strpbrk(dest, breakset);
|
||||
}
|
||||
|
||||
char *__wrap_strstr(const char *str, const char *substr) {
|
||||
return prvStrStr(str, substr);
|
||||
}
|
||||
|
||||
char *__wrap_strtok(char *str, const char *delim) {
|
||||
return prvStrtok(str, delim);
|
||||
}
|
||||
|
||||
void *__wrap_memchr(const void *ptr, int ch, size_t count) {
|
||||
return __rtl_memchr_v1_00(ptr, ch, count);
|
||||
}
|
||||
|
||||
int __wrap_memcmp(const void *lhs, const void *rhs, size_t count) {
|
||||
return _memcmp(lhs, rhs, count);
|
||||
}
|
||||
|
||||
void *__wrap_memcpy(void *dest, const void *src, size_t count) {
|
||||
return _memcpy(dest, src, count);
|
||||
}
|
||||
|
||||
void *__wrap_memmove(void *dest, const void *src, size_t count) {
|
||||
return __rtl_memmove_v1_00(dest, src, count);
|
||||
}
|
||||
|
||||
void *__wrap_memset(void *dest, int ch, size_t count) {
|
||||
return _memset(dest, ch, count);
|
||||
}
|
||||
|
||||
char *__wrap_strsep(char **stringp, const char *delim) {
|
||||
return _strsep(stringp, delim);
|
||||
}
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
Usually, functions available in C standard library should not be defined by the SDK. Instead, they should be included using GCC's headers, and implemented by the libc or wrapped and implemented in the SDK.
|
||||
|
||||
The following functions must not be defined by the SDK. Their presence makes conflicts due to incompatibility with C library, so they should be removed or disabled, and replaced with wrappers.
|
||||
The following functions should not be defined by the SDK. Their presence creates conflicts due to incompatibility with C library, so they should be removed or disabled, and replaced with wrappers.
|
||||
|
||||
Memory management functions should be wrapped and redirected to FreeRTOS (if possible). The necessary linker flags are added for all families (in `base.py`), and a FreeRTOS implementation of the wrappers are provided in `malloc.c` in the common core.
|
||||
Memory management functions must be wrapped and redirected to FreeRTOS. The necessary linker flags are already added for all families (in `base.py`), and a FreeRTOS implementation of the wrappers are provided in `malloc.c` in the common core. If the family doesn't use FreeRTOS, a separate implementation must be added.
|
||||
|
||||
Additionally, if the `printf` library is used in the chip family code, all other vendor-defined printf-like functions should be replaced with it.
|
||||
|
||||
@@ -28,6 +28,8 @@ long double strtold(const char *str, char **str_end);
|
||||
long long strtoll(const char *str, char **str_end, int base);
|
||||
unsigned long strtoul(const char *str, char **str_end, int base);
|
||||
unsigned long long strtoull(const char *str, char **str_end, int base);
|
||||
// stdlib.h / Random numbers
|
||||
int rand();
|
||||
|
||||
// string.h / Character classification
|
||||
int isalnum(int ch);
|
||||
@@ -81,6 +83,12 @@ int vprintf(const char *format, va_list vlist);
|
||||
int vsprintf(char *buffer, const char *format, va_list vlist);
|
||||
int vsnprintf(char *buffer, size_t bufsz, const char *format, va_list vlist);
|
||||
|
||||
// POSIX/BSD (from www.die.net)
|
||||
size_t strlcat(char *dst, const char *src, size_t size);
|
||||
size_t strlcpy(char *dst, const char *src, size_t size);
|
||||
size_t strnlen(const char *s, size_t maxlen);
|
||||
char *strsep(char **stringp, const char *delim);
|
||||
|
||||
// Non-stdlib
|
||||
_calloc_r
|
||||
_free_r
|
||||
@@ -89,10 +97,7 @@ _realloc_r
|
||||
atoui
|
||||
atoul
|
||||
atoull
|
||||
strlcpy
|
||||
strnicmp
|
||||
strnlen
|
||||
strsep
|
||||
zalloc
|
||||
|
||||
// Additional forbidden macros
|
||||
|
||||
Reference in New Issue
Block a user