Skip to content

Commit ae1428f

Browse files
committed
Runtime fix for native sim on zephyr along with project updates for other zephyr examples
1 parent ba7a22b commit ae1428f

14 files changed

Lines changed: 103 additions & 24 deletions

File tree

wolfssl/wolfcrypt/settings.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,9 +2650,37 @@ extern void uITRON4_free(void *p) ;
26502650
void *z_realloc(void *ptr, size_t size);
26512651
#define realloc z_realloc
26522652

2653+
#if KERNEL_VERSION_NUMBER >= 0x40100
2654+
/* Zephyr >= 4.1 removed CONFIG_NET_SOCKETS_POSIX_NAMES and the
2655+
* corresponding macro block in <zephyr/net/socket.h>.
2656+
* Define our own compile-time remapping to zsock_* so that wolfSSL
2657+
* always calls Zephyr's network stack directly, avoiding host-libc
2658+
* symbol conflicts on native_sim. */
2659+
#define socket zsock_socket
2660+
#define bind zsock_bind
2661+
#define connect zsock_connect
2662+
#define listen zsock_listen
2663+
#define accept zsock_accept
2664+
#define send zsock_send
2665+
#define recv zsock_recv
2666+
#define sendto zsock_sendto
2667+
#define recvfrom zsock_recvfrom
2668+
#define setsockopt zsock_setsockopt
2669+
#define getsockopt zsock_getsockopt
2670+
#define shutdown zsock_shutdown
2671+
#define close zsock_close
2672+
#define poll zsock_poll
2673+
#define getpeername zsock_getpeername
2674+
#define getsockname zsock_getsockname
2675+
#define inet_pton zsock_inet_pton
2676+
#define inet_ntop zsock_inet_ntop
2677+
#else
2678+
/* Zephyr < 4.1: define CONFIG_NET_SOCKETS_POSIX_NAMES so that
2679+
* <net/socket.h> provides the POSIX name remapping macros. */
26532680
#if !defined(CONFIG_NET_SOCKETS_POSIX_NAMES) && !defined(CONFIG_POSIX_API)
26542681
#define CONFIG_NET_SOCKETS_POSIX_NAMES
26552682
#endif
2683+
#endif
26562684
#endif /* WOLFSSL_ZEPHYR */
26572685

26582686
#ifdef WOLFSSL_IMX6

zephyr/samples/wolfssl_benchmark/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
cmake_minimum_required(VERSION 3.13.1)
2+
3+
# Select version-specific Kconfig fragment before loading Zephyr
4+
if(EXISTS $ENV{ZEPHYR_BASE}/VERSION)
5+
file(READ $ENV{ZEPHYR_BASE}/VERSION zephyr_version_file)
6+
string(REGEX MATCH "VERSION_MAJOR = ([0-9]+)" _ ${zephyr_version_file})
7+
set(ZEPHYR_VER_MAJOR ${CMAKE_MATCH_1})
8+
string(REGEX MATCH "VERSION_MINOR = ([0-9]+)" _ ${zephyr_version_file})
9+
set(ZEPHYR_VER_MINOR ${CMAKE_MATCH_1})
10+
endif()
11+
12+
if(ZEPHYR_VER_MAJOR GREATER_EQUAL 4 OR
13+
(ZEPHYR_VER_MAJOR EQUAL 3 AND
14+
ZEPHYR_VER_MINOR GREATER 5))
15+
set(EXTRA_CONF_FILE
16+
${CMAKE_CURRENT_SOURCE_DIR}/zephyr_v4.1.conf)
17+
else()
18+
set(EXTRA_CONF_FILE
19+
${CMAKE_CURRENT_SOURCE_DIR}/zephyr_legacy.conf)
20+
endif()
21+
222
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
323
project(wolfssl_benchmark)
424

zephyr/samples/wolfssl_benchmark/prj.conf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
CONFIG_MAIN_STACK_SIZE=32768
33
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192
44

5-
# Pthreads
6-
CONFIG_PTHREAD_IPC=y
7-
8-
# Clock for time()
9-
CONFIG_POSIX_CLOCK=y
10-
115
# TLS configuration
126
CONFIG_WOLFSSL=y
137
CONFIG_WOLFSSL_BUILTIN=y
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Zephyr < 4.1 POSIX options
2+
CONFIG_PTHREAD_IPC=y
3+
CONFIG_POSIX_CLOCK=y
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Zephyr >= 4.1 POSIX options
2+
CONFIG_POSIX_API=y

zephyr/samples/wolfssl_test/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
cmake_minimum_required(VERSION 3.13.1)
2+
3+
# Select version-specific Kconfig fragment before loading Zephyr
4+
if(EXISTS $ENV{ZEPHYR_BASE}/VERSION)
5+
file(READ $ENV{ZEPHYR_BASE}/VERSION zephyr_version_file)
6+
string(REGEX MATCH "VERSION_MAJOR = ([0-9]+)" _ ${zephyr_version_file})
7+
set(ZEPHYR_VER_MAJOR ${CMAKE_MATCH_1})
8+
string(REGEX MATCH "VERSION_MINOR = ([0-9]+)" _ ${zephyr_version_file})
9+
set(ZEPHYR_VER_MINOR ${CMAKE_MATCH_1})
10+
endif()
11+
12+
if(ZEPHYR_VER_MAJOR GREATER_EQUAL 4 OR
13+
(ZEPHYR_VER_MAJOR EQUAL 3 AND
14+
ZEPHYR_VER_MINOR GREATER 5))
15+
set(EXTRA_CONF_FILE
16+
${CMAKE_CURRENT_SOURCE_DIR}/zephyr_v4.1.conf)
17+
else()
18+
set(EXTRA_CONF_FILE
19+
${CMAKE_CURRENT_SOURCE_DIR}/zephyr_legacy.conf)
20+
endif()
21+
222
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
323
project(wolfssl_test)
424

zephyr/samples/wolfssl_test/prj-no-malloc.conf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
CONFIG_MAIN_STACK_SIZE=655360
33
#CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=65536
44

5-
# Pthreads
6-
CONFIG_PTHREAD_IPC=y
7-
8-
# Clock for time()
9-
CONFIG_POSIX_CLOCK=y
10-
115
# TLS configuration
126
CONFIG_WOLFSSL_SETTINGS_FILE="user_settings-no-malloc.h"
137
CONFIG_WOLFSSL=y

zephyr/samples/wolfssl_test/prj.conf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
CONFIG_MAIN_STACK_SIZE=32768
33
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=16384
44

5-
# Pthreads
6-
CONFIG_PTHREAD_IPC=y
7-
8-
# Clock for time()
9-
CONFIG_POSIX_CLOCK=y
10-
115
# TLS configuration
126
CONFIG_WOLFSSL=y
137
CONFIG_WOLFSSL_BUILTIN=y
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Zephyr < 4.1 POSIX options
2+
CONFIG_PTHREAD_IPC=y
3+
CONFIG_POSIX_CLOCK=y
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Zephyr >= 4.1 POSIX options
2+
CONFIG_POSIX_API=y

0 commit comments

Comments
 (0)