From 044291839129d5aacec3aadec17843f03f1661b2 Mon Sep 17 00:00:00 2001 From: night1rider Date: Wed, 11 Feb 2026 22:08:14 -0700 Subject: [PATCH] Add Zephyr 4.1+ build compatibility for wolfssl_tls_sock sample. Replace removed Kconfig options (PTHREAD_IPC, POSIX_CLOCK, NET_SOCKETS_POSIX_NAMES) with version-conditional config fragments and fix min/max macro collision with Zephyr's sys/util.h. --- .wolfssl_known_macro_extras | 3 ++ wolfcrypt/benchmark/benchmark.c | 6 ++- wolfcrypt/src/random.c | 24 ++++++---- wolfssl/test.h | 14 +++++- wolfssl/wolfcrypt/settings.h | 39 +++++++++++++++- wolfssl/wolfcrypt/wc_port.h | 46 +++++++++++++------ wolfssl/wolfio.h | 15 +++++- zephyr/CMakeLists.txt | 9 ++++ zephyr/Kconfig | 7 +++ zephyr/include.am | 12 +++++ .../samples/wolfssl_benchmark/CMakeLists.txt | 20 ++++++++ .../wolfssl_benchmark/boards/native_sim.conf | 2 + zephyr/samples/wolfssl_benchmark/prj.conf | 6 --- .../wolfssl_benchmark/zephyr_legacy.conf | 3 ++ .../wolfssl_benchmark/zephyr_v4.1.conf | 2 + zephyr/samples/wolfssl_test/CMakeLists.txt | 20 ++++++++ .../wolfssl_test/boards/native_sim.conf | 2 + .../samples/wolfssl_test/prj-no-malloc.conf | 6 --- zephyr/samples/wolfssl_test/prj.conf | 6 --- .../samples/wolfssl_test/zephyr_legacy.conf | 3 ++ zephyr/samples/wolfssl_test/zephyr_v4.1.conf | 2 + .../samples/wolfssl_tls_sock/CMakeLists.txt | 20 ++++++++ .../wolfssl_tls_sock/boards/native_sim.conf | 2 + zephyr/samples/wolfssl_tls_sock/prj.conf | 10 ---- .../samples/wolfssl_tls_sock/src/tls_sock.c | 5 +- .../wolfssl_tls_sock/zephyr_legacy.conf | 5 ++ .../samples/wolfssl_tls_sock/zephyr_v4.1.conf | 6 +++ .../samples/wolfssl_tls_thread/CMakeLists.txt | 20 ++++++++ .../wolfssl_tls_thread/boards/native_sim.conf | 2 + zephyr/samples/wolfssl_tls_thread/prj.conf | 6 --- .../wolfssl_tls_thread/zephyr_legacy.conf | 3 ++ .../wolfssl_tls_thread/zephyr_v4.1.conf | 2 + 32 files changed, 267 insertions(+), 61 deletions(-) create mode 100644 zephyr/samples/wolfssl_benchmark/boards/native_sim.conf create mode 100644 zephyr/samples/wolfssl_benchmark/zephyr_legacy.conf create mode 100644 zephyr/samples/wolfssl_benchmark/zephyr_v4.1.conf create mode 100644 zephyr/samples/wolfssl_test/boards/native_sim.conf create mode 100644 zephyr/samples/wolfssl_test/zephyr_legacy.conf create mode 100644 zephyr/samples/wolfssl_test/zephyr_v4.1.conf create mode 100644 zephyr/samples/wolfssl_tls_sock/boards/native_sim.conf create mode 100644 zephyr/samples/wolfssl_tls_sock/zephyr_legacy.conf create mode 100644 zephyr/samples/wolfssl_tls_sock/zephyr_v4.1.conf create mode 100644 zephyr/samples/wolfssl_tls_thread/boards/native_sim.conf create mode 100644 zephyr/samples/wolfssl_tls_thread/zephyr_legacy.conf create mode 100644 zephyr/samples/wolfssl_tls_thread/zephyr_v4.1.conf diff --git a/.wolfssl_known_macro_extras b/.wolfssl_known_macro_extras index 6c06931b99..be11b3066c 100644 --- a/.wolfssl_known_macro_extras +++ b/.wolfssl_known_macro_extras @@ -56,6 +56,7 @@ CONFIG_ARCH_TEGRA CONFIG_ARM CONFIG_ARM64 CONFIG_BOARD_NATIVE_POSIX +CONFIG_BOARD_NATIVE_SIM CONFIG_COMPILER_OPTIMIZATION_DEFAULT CONFIG_COMPILER_OPTIMIZATION_NONE CONFIG_COMPILER_OPTIMIZATION_PERF @@ -564,6 +565,7 @@ STSAFE_HOST_KEY_MAC STSAFE_I2C_BUS STSE_CONF_ECC_BRAINPOOL_P_256 STSE_CONF_ECC_BRAINPOOL_P_384 +SYS_CLOCK_REALTIME TASK_EXTRA_STACK_SIZE TCP_NODELAY TFM_ALREADY_SET @@ -1098,6 +1100,7 @@ __cplusplus __ghc__ __ghs__ __has_attribute +__has_include __hpux__ __i386 __i386__ diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index fea45db55e..8df76d0ad7 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -15934,7 +15934,11 @@ void bench_sphincsKeySign(byte level, byte optim) int64_t t; (void)reset; #if defined(CONFIG_ARCH_POSIX) - k_cpu_idle(); + #if defined(CONFIG_BOARD_NATIVE_SIM) + k_msleep(1); + #else + k_cpu_idle(); + #endif #endif t = k_uptime_get(); /* returns current uptime in milliseconds */ return (double)(t / 1000); diff --git a/wolfcrypt/src/random.c b/wolfcrypt/src/random.c index 6886a58692..5340a0b271 100644 --- a/wolfcrypt/src/random.c +++ b/wolfcrypt/src/random.c @@ -3447,7 +3447,17 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) #elif defined(WOLFSSL_ZEPHYR) - #include + #ifdef __has_include + #if __has_include() + #include + #else + #include + #endif + #else + #include + #endif + + #include #if KERNEL_VERSION_NUMBER >= 0x30500 #include @@ -3459,14 +3469,12 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) #endif #endif - #ifndef _POSIX_C_SOURCE - #if KERNEL_VERSION_NUMBER >= 0x30100 - #include - #else - #include - #endif - #else + #if KERNEL_VERSION_NUMBER >= 0x40300 #include + #elif KERNEL_VERSION_NUMBER >= 0x30100 + #include + #else + #include #endif int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz) diff --git a/wolfssl/test.h b/wolfssl/test.h index 5a191aa27f..4e1c8e0a2a 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -188,7 +188,15 @@ #include #define SOCKET_T int #elif defined(WOLFSSL_ZEPHYR) - #include + #ifdef __has_include + #if __has_include() + #include + #else + #include + #endif + #else + #include + #endif #include #include #if KERNEL_VERSION_NUMBER >= 0x30100 @@ -209,9 +217,10 @@ #endif #endif #define SOCKET_T int - #define SOL_SOCKET 1 #define WOLFSSL_USE_GETADDRINFO + #if !defined(CONFIG_POSIX_API) + #define SOL_SOCKET 1 static unsigned long inet_addr(const char *cp) { unsigned int a[4]; unsigned long ret; @@ -227,6 +236,7 @@ ret = ((a[3]<<24) + (a[2]<<16) + (a[1]<<8) + a[0]) ; return(ret) ; } + #endif #elif defined(NETOS) #include #include diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index 503fade1d9..ffae6b60af 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -2621,7 +2621,15 @@ extern void uITRON4_free(void *p) ; } /* extern "C" */ #endif - #include + #ifdef __has_include + #if __has_include() + #include + #else + #include + #endif + #else + #include + #endif #if KERNEL_VERSION_NUMBER >= 0x30100 #include #include @@ -2649,9 +2657,38 @@ extern void uITRON4_free(void *p) ; void *z_realloc(void *ptr, size_t size); #define realloc z_realloc + #if KERNEL_VERSION_NUMBER >= 0x40100 + /* Zephyr >= 4.1 removed CONFIG_NET_SOCKETS_POSIX_NAMES and the + * corresponding macro block in . + * Define our own compile-time remapping to zsock_* so that wolfSSL + * always calls Zephyr's network stack directly, avoiding host-libc + * symbol conflicts on native_sim. */ + #define socket zsock_socket + #define bind zsock_bind + #define connect zsock_connect + #define listen zsock_listen + #define accept zsock_accept + #define send zsock_send + #define recv zsock_recv + #define sendto zsock_sendto + #define recvfrom zsock_recvfrom + #define setsockopt zsock_setsockopt + #define getsockopt zsock_getsockopt + #define shutdown zsock_shutdown + #define getpeername zsock_getpeername + #define getsockname zsock_getsockname + /* Note: close, poll, inet_pton, inet_ntop are NOT remapped here. + * They are general POSIX functions still declared in Zephyr's POSIX + * headers; redefining them conflicts with __syscall declarations in + * . close is handled via CloseSocket in wolfio.h, + * inet_pton/inet_ntop via XINET_PTON/XINET_NTOP in wolfio.h. */ + #else + /* Zephyr < 4.1: define CONFIG_NET_SOCKETS_POSIX_NAMES so that + * provides the POSIX name remapping macros. */ #if !defined(CONFIG_NET_SOCKETS_POSIX_NAMES) && !defined(CONFIG_POSIX_API) #define CONFIG_NET_SOCKETS_POSIX_NAMES #endif + #endif #endif /* WOLFSSL_ZEPHYR */ #ifdef WOLFSSL_IMX6 diff --git a/wolfssl/wolfcrypt/wc_port.h b/wolfssl/wolfcrypt/wc_port.h index cb0f35f1e2..4f7d373ab9 100644 --- a/wolfssl/wolfcrypt/wc_port.h +++ b/wolfssl/wolfcrypt/wc_port.h @@ -301,19 +301,34 @@ } /* extern "C" */ #endif - #include + #ifdef __has_include + #if __has_include() + #include + #else + #include + #endif + #else + #include + #endif + /* Include sys/types.h early so host libc sets __timer_t_defined + * before Zephyr's posix_types.h can define a conflicting timer_t */ + #include #ifndef SINGLE_THREADED #if !defined(CONFIG_PTHREAD_IPC) && !defined(CONFIG_POSIX_THREADS) #error "Threading needs CONFIG_PTHREAD_IPC / CONFIG_POSIX_THREADS" #endif #if KERNEL_VERSION_NUMBER >= 0x30100 #include - #include - #include + #ifndef CONFIG_ARCH_POSIX + #include + #include + #endif #else #include - #include - #include + #ifndef CONFIG_ARCH_POSIX + #include + #include + #endif #endif #endif @@ -1505,15 +1520,20 @@ WOLFSSL_ABI WOLFSSL_API int wolfCrypt_Cleanup(void); } /* extern "C" */ #endif - #include - #ifndef _POSIX_C_SOURCE - #if KERNEL_VERSION_NUMBER >= 0x30100 - #include - #else - #include - #endif - #else + #if KERNEL_VERSION_NUMBER >= 0x40300 #include + #elif KERNEL_VERSION_NUMBER >= 0x30100 + #include + #else + #include + #endif + + #ifndef CLOCK_REALTIME + #ifdef SYS_CLOCK_REALTIME + #define CLOCK_REALTIME SYS_CLOCK_REALTIME + #define clock_gettime sys_clock_gettime + #define clock_settime sys_clock_settime + #endif #endif #if defined(CONFIG_RTC) diff --git a/wolfssl/wolfio.h b/wolfssl/wolfio.h index 97bdbf5cb9..c215fa0b89 100644 --- a/wolfssl/wolfio.h +++ b/wolfssl/wolfio.h @@ -180,7 +180,15 @@ } /* extern "C" */ #endif - #include + #ifdef __has_include + #if __has_include() + #include + #else + #include + #endif + #else + #include + #endif #if KERNEL_VERSION_NUMBER >= 0x30100 #include #ifdef CONFIG_POSIX_API @@ -623,6 +631,11 @@ WOLFSSL_API int wolfIO_RecvFrom(SOCKET_T sd, WOLFSSL_BIO_ADDR *addr, char *buf, #define CloseSocket(s) closesocket(s) #endif #define StartTCP() WC_DO_NOTHING +#elif defined(WOLFSSL_ZEPHYR) && KERNEL_VERSION_NUMBER >= 0x40100 + #ifndef CloseSocket + #define CloseSocket(s) zsock_close(s) + #endif + #define StartTCP() WC_DO_NOTHING #else #ifndef CloseSocket #define CloseSocket(s) close(s) diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index aeb714b946..35b8a76565 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -186,6 +186,15 @@ if(CONFIG_WOLFSSL) target_compile_definitions(wolfSSL INTERFACE WOLFSSL_ZEPHYR) target_compile_definitions(wolfSSL INTERFACE WOLFSSL_USER_SETTINGS) + + if(NOT CONFIG_WOLFSSL_NO_HAVE_MIN_MAX AND + (KERNEL_VERSION_MAJOR GREATER_EQUAL 5 OR + (KERNEL_VERSION_MAJOR EQUAL 4 AND + KERNEL_VERSION_MINOR GREATER_EQUAL 3))) + target_compile_definitions(wolfSSL INTERFACE + WOLFSSL_HAVE_MIN + WOLFSSL_HAVE_MAX) + endif() if(CONFIG_WOLFSSL_DEBUG) target_compile_definitions(wolfSSL INTERFACE DEBUG_WOLFSSL) zephyr_library_compile_options(-g3 -O0) diff --git a/zephyr/Kconfig b/zephyr/Kconfig index 9863454ffc..0de97943cb 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -112,6 +112,13 @@ config WOLFCRYPT_INTELASM help wolfCrypt Intel Aassembly support (AVX/AVX2/AESNI) +config WOLFSSL_NO_HAVE_MIN_MAX + bool "Force wolfSSL to use its own min/max" + help + Disable this if Zephyr min()/max() macros cause + issues. By default wolfSSL defers to Zephyr's + min/max on >= 4.3. + config WOLFSSL_DEBUG bool "wolfSSL debug activation" depends on WOLFSSL_BUILTIN diff --git a/zephyr/include.am b/zephyr/include.am index ef67bcc108..6c602ecd25 100644 --- a/zephyr/include.am +++ b/zephyr/include.am @@ -13,31 +13,43 @@ EXTRA_DIST+= zephyr/README.md EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/ EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/CMakeLists.txt EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/README +EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/boards/native_sim.conf EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/boards/nrf5340dk_nrf5340_cpuapp.conf EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/boards/nrf5340dk_nrf5340_cpuapp_ns.conf EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/install_test.sh EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/prj.conf EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/sample.yaml +EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/zephyr_legacy.conf +EXTRA_DIST+= zephyr/samples/wolfssl_benchmark/zephyr_v4.1.conf EXTRA_DIST+= zephyr/samples/wolfssl_test/CMakeLists.txt EXTRA_DIST+= zephyr/samples/wolfssl_test/README +EXTRA_DIST+= zephyr/samples/wolfssl_test/boards/native_sim.conf EXTRA_DIST+= zephyr/samples/wolfssl_test/boards/nrf5340dk_nrf5340_cpuapp.conf EXTRA_DIST+= zephyr/samples/wolfssl_test/boards/nrf5340dk_nrf5340_cpuapp_ns.conf EXTRA_DIST+= zephyr/samples/wolfssl_test/install_test.sh EXTRA_DIST+= zephyr/samples/wolfssl_test/prj.conf EXTRA_DIST+= zephyr/samples/wolfssl_test/sample.yaml +EXTRA_DIST+= zephyr/samples/wolfssl_test/zephyr_legacy.conf +EXTRA_DIST+= zephyr/samples/wolfssl_test/zephyr_v4.1.conf EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/CMakeLists.txt EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/README +EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/boards/native_sim.conf EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/install_sample.sh EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/prj.conf EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/sample.yaml EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/src +EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/zephyr_legacy.conf +EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/zephyr_v4.1.conf EXTRA_DIST+= zephyr/samples/wolfssl_tls_sock/src/tls_sock.c EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/CMakeLists.txt EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/README +EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/boards/native_sim.conf EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/boards/nrf5340dk_nrf5340_cpuapp.conf EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/boards/nrf5340dk_nrf5340_cpuapp_ns.conf EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/install_sample.sh EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/prj.conf EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/sample.yaml EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/src +EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/zephyr_legacy.conf +EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/zephyr_v4.1.conf EXTRA_DIST+= zephyr/samples/wolfssl_tls_thread/src/tls_threaded.c diff --git a/zephyr/samples/wolfssl_benchmark/CMakeLists.txt b/zephyr/samples/wolfssl_benchmark/CMakeLists.txt index 1b68e1bfb7..7dadb8e37e 100644 --- a/zephyr/samples/wolfssl_benchmark/CMakeLists.txt +++ b/zephyr/samples/wolfssl_benchmark/CMakeLists.txt @@ -1,4 +1,24 @@ cmake_minimum_required(VERSION 3.13.1) + +# Select version-specific Kconfig fragment before loading Zephyr +if(EXISTS $ENV{ZEPHYR_BASE}/VERSION) + file(READ $ENV{ZEPHYR_BASE}/VERSION zephyr_version_file) + string(REGEX MATCH "VERSION_MAJOR = ([0-9]+)" _ ${zephyr_version_file}) + set(ZEPHYR_VER_MAJOR ${CMAKE_MATCH_1}) + string(REGEX MATCH "VERSION_MINOR = ([0-9]+)" _ ${zephyr_version_file}) + set(ZEPHYR_VER_MINOR ${CMAKE_MATCH_1}) +endif() + +if(ZEPHYR_VER_MAJOR GREATER_EQUAL 4 OR + (ZEPHYR_VER_MAJOR EQUAL 3 AND + ZEPHYR_VER_MINOR GREATER 5)) + set(OVERLAY_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/zephyr_v4.1.conf) +else() + set(OVERLAY_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/zephyr_legacy.conf) +endif() + find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(wolfssl_benchmark) diff --git a/zephyr/samples/wolfssl_benchmark/boards/native_sim.conf b/zephyr/samples/wolfssl_benchmark/boards/native_sim.conf new file mode 100644 index 0000000000..248d047069 --- /dev/null +++ b/zephyr/samples/wolfssl_benchmark/boards/native_sim.conf @@ -0,0 +1,2 @@ +# native_sim needs a larger malloc arena for thread stack allocation +CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=131072 diff --git a/zephyr/samples/wolfssl_benchmark/prj.conf b/zephyr/samples/wolfssl_benchmark/prj.conf index 0179880249..b542c63b63 100644 --- a/zephyr/samples/wolfssl_benchmark/prj.conf +++ b/zephyr/samples/wolfssl_benchmark/prj.conf @@ -2,12 +2,6 @@ CONFIG_MAIN_STACK_SIZE=32768 CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192 -# Pthreads -CONFIG_PTHREAD_IPC=y - -# Clock for time() -CONFIG_POSIX_CLOCK=y - # TLS configuration CONFIG_WOLFSSL=y CONFIG_WOLFSSL_BUILTIN=y diff --git a/zephyr/samples/wolfssl_benchmark/zephyr_legacy.conf b/zephyr/samples/wolfssl_benchmark/zephyr_legacy.conf new file mode 100644 index 0000000000..ab3026748b --- /dev/null +++ b/zephyr/samples/wolfssl_benchmark/zephyr_legacy.conf @@ -0,0 +1,3 @@ +# Zephyr < 4.1 POSIX options +CONFIG_PTHREAD_IPC=y +CONFIG_POSIX_CLOCK=y diff --git a/zephyr/samples/wolfssl_benchmark/zephyr_v4.1.conf b/zephyr/samples/wolfssl_benchmark/zephyr_v4.1.conf new file mode 100644 index 0000000000..23383009c5 --- /dev/null +++ b/zephyr/samples/wolfssl_benchmark/zephyr_v4.1.conf @@ -0,0 +1,2 @@ +# Zephyr >= 4.1 POSIX options +CONFIG_POSIX_API=y diff --git a/zephyr/samples/wolfssl_test/CMakeLists.txt b/zephyr/samples/wolfssl_test/CMakeLists.txt index bae4c16547..5ddf1b9a87 100644 --- a/zephyr/samples/wolfssl_test/CMakeLists.txt +++ b/zephyr/samples/wolfssl_test/CMakeLists.txt @@ -1,4 +1,24 @@ cmake_minimum_required(VERSION 3.13.1) + +# Select version-specific Kconfig fragment before loading Zephyr +if(EXISTS $ENV{ZEPHYR_BASE}/VERSION) + file(READ $ENV{ZEPHYR_BASE}/VERSION zephyr_version_file) + string(REGEX MATCH "VERSION_MAJOR = ([0-9]+)" _ ${zephyr_version_file}) + set(ZEPHYR_VER_MAJOR ${CMAKE_MATCH_1}) + string(REGEX MATCH "VERSION_MINOR = ([0-9]+)" _ ${zephyr_version_file}) + set(ZEPHYR_VER_MINOR ${CMAKE_MATCH_1}) +endif() + +if(ZEPHYR_VER_MAJOR GREATER_EQUAL 4 OR + (ZEPHYR_VER_MAJOR EQUAL 3 AND + ZEPHYR_VER_MINOR GREATER 5)) + set(OVERLAY_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/zephyr_v4.1.conf) +else() + set(OVERLAY_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/zephyr_legacy.conf) +endif() + find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(wolfssl_test) diff --git a/zephyr/samples/wolfssl_test/boards/native_sim.conf b/zephyr/samples/wolfssl_test/boards/native_sim.conf new file mode 100644 index 0000000000..248d047069 --- /dev/null +++ b/zephyr/samples/wolfssl_test/boards/native_sim.conf @@ -0,0 +1,2 @@ +# native_sim needs a larger malloc arena for thread stack allocation +CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=131072 diff --git a/zephyr/samples/wolfssl_test/prj-no-malloc.conf b/zephyr/samples/wolfssl_test/prj-no-malloc.conf index 42f98d431d..e9ff7cf801 100644 --- a/zephyr/samples/wolfssl_test/prj-no-malloc.conf +++ b/zephyr/samples/wolfssl_test/prj-no-malloc.conf @@ -2,12 +2,6 @@ CONFIG_MAIN_STACK_SIZE=655360 #CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=65536 -# Pthreads -CONFIG_PTHREAD_IPC=y - -# Clock for time() -CONFIG_POSIX_CLOCK=y - # TLS configuration CONFIG_WOLFSSL_SETTINGS_FILE="user_settings-no-malloc.h" CONFIG_WOLFSSL=y diff --git a/zephyr/samples/wolfssl_test/prj.conf b/zephyr/samples/wolfssl_test/prj.conf index 38b1ce49b4..215a93c49c 100644 --- a/zephyr/samples/wolfssl_test/prj.conf +++ b/zephyr/samples/wolfssl_test/prj.conf @@ -2,12 +2,6 @@ CONFIG_MAIN_STACK_SIZE=32768 CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=16384 -# Pthreads -CONFIG_PTHREAD_IPC=y - -# Clock for time() -CONFIG_POSIX_CLOCK=y - # TLS configuration CONFIG_WOLFSSL=y CONFIG_WOLFSSL_BUILTIN=y diff --git a/zephyr/samples/wolfssl_test/zephyr_legacy.conf b/zephyr/samples/wolfssl_test/zephyr_legacy.conf new file mode 100644 index 0000000000..ab3026748b --- /dev/null +++ b/zephyr/samples/wolfssl_test/zephyr_legacy.conf @@ -0,0 +1,3 @@ +# Zephyr < 4.1 POSIX options +CONFIG_PTHREAD_IPC=y +CONFIG_POSIX_CLOCK=y diff --git a/zephyr/samples/wolfssl_test/zephyr_v4.1.conf b/zephyr/samples/wolfssl_test/zephyr_v4.1.conf new file mode 100644 index 0000000000..23383009c5 --- /dev/null +++ b/zephyr/samples/wolfssl_test/zephyr_v4.1.conf @@ -0,0 +1,2 @@ +# Zephyr >= 4.1 POSIX options +CONFIG_POSIX_API=y diff --git a/zephyr/samples/wolfssl_tls_sock/CMakeLists.txt b/zephyr/samples/wolfssl_tls_sock/CMakeLists.txt index a1208f5029..bdd894eda7 100644 --- a/zephyr/samples/wolfssl_tls_sock/CMakeLists.txt +++ b/zephyr/samples/wolfssl_tls_sock/CMakeLists.txt @@ -1,4 +1,24 @@ cmake_minimum_required(VERSION 3.13.1) + +# Select version-specific Kconfig fragment before loading Zephyr +if(EXISTS $ENV{ZEPHYR_BASE}/VERSION) + file(READ $ENV{ZEPHYR_BASE}/VERSION zephyr_version_file) + string(REGEX MATCH "VERSION_MAJOR = ([0-9]+)" _ ${zephyr_version_file}) + set(ZEPHYR_VER_MAJOR ${CMAKE_MATCH_1}) + string(REGEX MATCH "VERSION_MINOR = ([0-9]+)" _ ${zephyr_version_file}) + set(ZEPHYR_VER_MINOR ${CMAKE_MATCH_1}) +endif() + +if(ZEPHYR_VER_MAJOR GREATER_EQUAL 4 OR + (ZEPHYR_VER_MAJOR EQUAL 3 AND + ZEPHYR_VER_MINOR GREATER 5)) + set(OVERLAY_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/zephyr_v4.1.conf) +else() + set(OVERLAY_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/zephyr_legacy.conf) +endif() + include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) project(wolfssl_tls_sock) diff --git a/zephyr/samples/wolfssl_tls_sock/boards/native_sim.conf b/zephyr/samples/wolfssl_tls_sock/boards/native_sim.conf new file mode 100644 index 0000000000..248d047069 --- /dev/null +++ b/zephyr/samples/wolfssl_tls_sock/boards/native_sim.conf @@ -0,0 +1,2 @@ +# native_sim needs a larger malloc arena for thread stack allocation +CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=131072 diff --git a/zephyr/samples/wolfssl_tls_sock/prj.conf b/zephyr/samples/wolfssl_tls_sock/prj.conf index 549bc07ab0..a51becba37 100644 --- a/zephyr/samples/wolfssl_tls_sock/prj.conf +++ b/zephyr/samples/wolfssl_tls_sock/prj.conf @@ -4,22 +4,12 @@ CONFIG_ENTROPY_GENERATOR=y CONFIG_INIT_STACKS=y CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=8192 -# General config -CONFIG_NEWLIB_LIBC=y - -# Pthreads -CONFIG_PTHREAD_IPC=y - -# Clock for time() -CONFIG_POSIX_CLOCK=y - # Networking config CONFIG_NETWORKING=y CONFIG_NET_IPV4=y CONFIG_NET_IPV6=n CONFIG_NET_TCP=y CONFIG_NET_SOCKETS=y -CONFIG_NET_SOCKETS_POSIX_NAMES=y CONFIG_NET_TEST=y CONFIG_NET_LOOPBACK=y diff --git a/zephyr/samples/wolfssl_tls_sock/src/tls_sock.c b/zephyr/samples/wolfssl_tls_sock/src/tls_sock.c index 138e266193..e6cab37ead 100644 --- a/zephyr/samples/wolfssl_tls_sock/src/tls_sock.c +++ b/zephyr/samples/wolfssl_tls_sock/src/tls_sock.c @@ -35,6 +35,8 @@ #define STATIC_MEM_SIZE (256*1024) #define MAX_SEND_SIZE 256 +K_SEM_DEFINE(server_ready, 0, 1); + #ifdef WOLFSSL_STATIC_MEMORY static WOLFSSL_HEAP_HINT* HEAP_HINT_SERVER; static WOLFSSL_HEAP_HINT* HEAP_HINT_CLIENT; @@ -323,6 +325,7 @@ int wolfssl_server_accept_tcp(WOLFSSL* ssl, SOCKET_T* fd, SOCKET_T* acceptfd) *fd = sockfd; printf("Server Listen\n"); listen(sockfd, 5); + k_sem_give(&server_ready); if (WOLFSSL_SOCKET_IS_INVALID(sockfd)) ret = -1; } @@ -512,7 +515,7 @@ int main() return -1; } - k_sleep(Z_TIMEOUT_TICKS(100)); + k_sem_take(&server_ready, K_FOREVER); client_thread(); /* Join is not working in qemu when the thread is still active. Wait for it * to shut down to join it. */ diff --git a/zephyr/samples/wolfssl_tls_sock/zephyr_legacy.conf b/zephyr/samples/wolfssl_tls_sock/zephyr_legacy.conf new file mode 100644 index 0000000000..d7760060a5 --- /dev/null +++ b/zephyr/samples/wolfssl_tls_sock/zephyr_legacy.conf @@ -0,0 +1,5 @@ +# Zephyr < 4.1 POSIX and libc options +CONFIG_NEWLIB_LIBC=y +CONFIG_PTHREAD_IPC=y +CONFIG_POSIX_CLOCK=y +CONFIG_NET_SOCKETS_POSIX_NAMES=y diff --git a/zephyr/samples/wolfssl_tls_sock/zephyr_v4.1.conf b/zephyr/samples/wolfssl_tls_sock/zephyr_v4.1.conf new file mode 100644 index 0000000000..7ae8645055 --- /dev/null +++ b/zephyr/samples/wolfssl_tls_sock/zephyr_v4.1.conf @@ -0,0 +1,6 @@ +# Zephyr >= 4.1 POSIX and libc options +CONFIG_NEWLIB_LIBC=y +CONFIG_POSIX_API=y + +# NET_LOOPBACK depends on NET_DRIVERS in Zephyr >= 4.1 +CONFIG_NET_DRIVERS=y diff --git a/zephyr/samples/wolfssl_tls_thread/CMakeLists.txt b/zephyr/samples/wolfssl_tls_thread/CMakeLists.txt index 55c2199ec5..ec2d0a5392 100644 --- a/zephyr/samples/wolfssl_tls_thread/CMakeLists.txt +++ b/zephyr/samples/wolfssl_tls_thread/CMakeLists.txt @@ -1,4 +1,24 @@ cmake_minimum_required(VERSION 3.13.1) + +# Select version-specific Kconfig fragment before loading Zephyr +if(EXISTS $ENV{ZEPHYR_BASE}/VERSION) + file(READ $ENV{ZEPHYR_BASE}/VERSION zephyr_version_file) + string(REGEX MATCH "VERSION_MAJOR = ([0-9]+)" _ ${zephyr_version_file}) + set(ZEPHYR_VER_MAJOR ${CMAKE_MATCH_1}) + string(REGEX MATCH "VERSION_MINOR = ([0-9]+)" _ ${zephyr_version_file}) + set(ZEPHYR_VER_MINOR ${CMAKE_MATCH_1}) +endif() + +if(ZEPHYR_VER_MAJOR GREATER_EQUAL 4 OR + (ZEPHYR_VER_MAJOR EQUAL 3 AND + ZEPHYR_VER_MINOR GREATER 5)) + set(OVERLAY_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/zephyr_v4.1.conf) +else() + set(OVERLAY_CONFIG + ${CMAKE_CURRENT_SOURCE_DIR}/zephyr_legacy.conf) +endif() + find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(wolfssl_tls_threaded) diff --git a/zephyr/samples/wolfssl_tls_thread/boards/native_sim.conf b/zephyr/samples/wolfssl_tls_thread/boards/native_sim.conf new file mode 100644 index 0000000000..248d047069 --- /dev/null +++ b/zephyr/samples/wolfssl_tls_thread/boards/native_sim.conf @@ -0,0 +1,2 @@ +# native_sim needs a larger malloc arena for thread stack allocation +CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=131072 diff --git a/zephyr/samples/wolfssl_tls_thread/prj.conf b/zephyr/samples/wolfssl_tls_thread/prj.conf index 185a7b24c0..6fb19d3aa9 100644 --- a/zephyr/samples/wolfssl_tls_thread/prj.conf +++ b/zephyr/samples/wolfssl_tls_thread/prj.conf @@ -5,12 +5,6 @@ CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_INIT_STACKS=y CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=131072 -# Pthreads -CONFIG_PTHREAD_IPC=y - -# Clock for time() -CONFIG_POSIX_CLOCK=y - # Networking CONFIG_NETWORKING=y CONFIG_NET_TEST=y diff --git a/zephyr/samples/wolfssl_tls_thread/zephyr_legacy.conf b/zephyr/samples/wolfssl_tls_thread/zephyr_legacy.conf new file mode 100644 index 0000000000..ab3026748b --- /dev/null +++ b/zephyr/samples/wolfssl_tls_thread/zephyr_legacy.conf @@ -0,0 +1,3 @@ +# Zephyr < 4.1 POSIX options +CONFIG_PTHREAD_IPC=y +CONFIG_POSIX_CLOCK=y diff --git a/zephyr/samples/wolfssl_tls_thread/zephyr_v4.1.conf b/zephyr/samples/wolfssl_tls_thread/zephyr_v4.1.conf new file mode 100644 index 0000000000..23383009c5 --- /dev/null +++ b/zephyr/samples/wolfssl_tls_thread/zephyr_v4.1.conf @@ -0,0 +1,2 @@ +# Zephyr >= 4.1 POSIX options +CONFIG_POSIX_API=y