mirror of https://github.com/wolfSSL/wolfssh.git
Port Zephyr test sample to 3.4.0 and 4.4.0
Zephyr 3.5 moved the RAM disk driver from Kconfig to devicetree and 4.1 replaced CONFIG_NET_SOCKETS_POSIX_NAMES with CONFIG_POSIX_API. Port the sample to the new APIs while keeping it buildable on older Zephyr. - add ramdisk.overlay (zephyr,ram-disk node) for the FS scenarios; drop CONFIG_DISK_RAM_VOLUME_SIZE - switch to CONFIG_POSIX_API; include the POSIX time/select/socket/netdb headers in test.h and port.h, gated on ZEPHYR_VERSION_CODE >= 4.1.0 so older Zephyr keeps the BSD names from <zephyr/net/socket.h> - select RAM disk (overlay >= 3.5, else CONFIG_DISK_RAM_VOLUME_SIZE) and POSIX (CONFIG_POSIX_API >= 4.1, else the legacy symbols) in CMakeLists.txt, with ramdisk_legacy.conf / posix_legacy.conf fallbacks - tests, nofs and kbi scenarios pass on qemu_x86 with Zephyr 3.4.0 (SDK 0.16.1) and 4.4.0 (SDK 1.0.0)pull/1051/head
parent
ac762368ac
commit
8d97ee9250
|
|
@ -367,6 +367,13 @@ extern "C" {
|
|||
#elif defined(WOLFSSH_ZEPHYR)
|
||||
|
||||
#include <zephyr/fs/fs.h>
|
||||
#include <zephyr/version.h>
|
||||
#if ZEPHYR_VERSION_CODE >= ZEPHYR_VERSION(4, 1, 0)
|
||||
/* struct timeval: pre-4.1 it arrived via the socket headers when
|
||||
* NET_SOCKETS_POSIX_NAMES was set; 4.1+ needs the POSIX header
|
||||
* (CONFIG_POSIX_API). */
|
||||
#include <zephyr/posix/sys/time.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
|
@ -393,7 +400,7 @@ extern "C" {
|
|||
#define WFGETS(b,s,f) NULL /* Not ported yet */
|
||||
#undef WFPUTS
|
||||
#define WFPUTS(b,s) EOF /* Not ported yet */
|
||||
#define WUTIMES(a,b) (0) /* Not ported yet */
|
||||
#define WUTIMES(a,b) ((void)(a),(void)(b),0) /* Not ported yet */
|
||||
#define WCHDIR(fs,b) z_fs_chdir((b))
|
||||
|
||||
#elif defined(MICROCHIP_MPLAB_HARMONY)
|
||||
|
|
|
|||
|
|
@ -128,10 +128,21 @@
|
|||
#define NUM_SOCKETS 5
|
||||
#elif defined(WOLFSSH_ZEPHYR)
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/version.h>
|
||||
#include <zephyr/posix/posix_types.h>
|
||||
#include <zephyr/posix/pthread.h>
|
||||
#include <zephyr/posix/fcntl.h>
|
||||
#include <zephyr/net/socket.h>
|
||||
#if ZEPHYR_VERSION_CODE >= ZEPHYR_VERSION(4, 1, 0)
|
||||
/* Zephyr 4.1 removed NET_SOCKETS_POSIX_NAMES; the BSD/POSIX names
|
||||
* (fd_set, select(), struct timeval, getaddrinfo()) now come from
|
||||
* the POSIX headers, enabled via CONFIG_POSIX_API. Older Zephyr
|
||||
* exposes them through <zephyr/net/socket.h> above. */
|
||||
#include <zephyr/posix/sys/time.h>
|
||||
#include <zephyr/posix/sys/select.h>
|
||||
#include <zephyr/posix/sys/socket.h>
|
||||
#include <zephyr/posix/netdb.h>
|
||||
#endif
|
||||
#include <zephyr/sys/printk.h>
|
||||
#include <zephyr/sys/util.h>
|
||||
#include <stdlib.h>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,44 @@
|
|||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
# Need the Zephyr version before find_package (KERNEL_VERSION_* is not set yet)
|
||||
# to gate the RAM disk / POSIX config below; parse $ZEPHYR_BASE/VERSION directly.
|
||||
# find_package() tolerates an unset ZEPHYR_BASE, but reading VERSION does not,
|
||||
# so check it here rather than letting file(STRINGS) fail on "/VERSION".
|
||||
if(NOT DEFINED ENV{ZEPHYR_BASE} OR NOT EXISTS "$ENV{ZEPHYR_BASE}/VERSION")
|
||||
message(FATAL_ERROR
|
||||
"ZEPHYR_BASE must be set in the environment (west build and zephyr-env.sh "
|
||||
"both do this); this sample needs it to detect the Zephyr version.")
|
||||
endif()
|
||||
file(STRINGS "$ENV{ZEPHYR_BASE}/VERSION" zephyr_version_lines)
|
||||
foreach(line ${zephyr_version_lines})
|
||||
if("${line}" MATCHES "VERSION_MAJOR[ \t]*=[ \t]*([0-9]+)")
|
||||
set(ZEPHYR_VER_MAJOR ${CMAKE_MATCH_1})
|
||||
elseif("${line}" MATCHES "VERSION_MINOR[ \t]*=[ \t]*([0-9]+)")
|
||||
set(ZEPHYR_VER_MINOR ${CMAKE_MATCH_1})
|
||||
endif()
|
||||
endforeach()
|
||||
if(NOT DEFINED ZEPHYR_VER_MAJOR OR NOT DEFINED ZEPHYR_VER_MINOR)
|
||||
message(FATAL_ERROR
|
||||
"Could not determine Zephyr version from $ENV{ZEPHYR_BASE}/VERSION")
|
||||
endif()
|
||||
set(ZEPHYR_VER "${ZEPHYR_VER_MAJOR}.${ZEPHYR_VER_MINOR}")
|
||||
|
||||
# RAM disk (devicetree on >= 3.5, Kconfig before): only the filesystem-backed
|
||||
# scenarios need it, not the nofs build.
|
||||
if(NOT "${CONF_FILE}" MATCHES "nofs")
|
||||
if(ZEPHYR_VER VERSION_LESS 3.5)
|
||||
list(APPEND EXTRA_CONF_FILE ${CMAKE_CURRENT_SOURCE_DIR}/ramdisk_legacy.conf)
|
||||
else()
|
||||
list(APPEND EXTRA_DTC_OVERLAY_FILE ${CMAKE_CURRENT_SOURCE_DIR}/ramdisk.overlay)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# CONFIG_POSIX_API (in prj*.conf) covers POSIX sockets/pthreads/clock on
|
||||
# >= 4.1; older releases need the symbols the 4.1 reorg removed.
|
||||
if(ZEPHYR_VER VERSION_LESS 4.1)
|
||||
list(APPEND EXTRA_CONF_FILE ${CMAKE_CURRENT_SOURCE_DIR}/posix_legacy.conf)
|
||||
endif()
|
||||
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(wolfssl_tests)
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
# Pre-4.1: restore the POSIX symbols the 4.1 reorg folded into CONFIG_POSIX_API.
|
||||
CONFIG_POSIX_API=n
|
||||
CONFIG_PTHREAD_IPC=y
|
||||
CONFIG_POSIX_CLOCK=y
|
||||
CONFIG_NET_SOCKETS_POSIX_NAMES=y
|
||||
|
|
@ -9,11 +9,13 @@ CONFIG_WOLFSSH=y
|
|||
CONFIG_WOLFSSH_SETTINGS_FILE="samples/tests/wolfssh_user_settings.h"
|
||||
CONFIG_WOLFSSH_SFTP_DEFAULT_DIR="/RAM:"
|
||||
|
||||
# Pthreads
|
||||
CONFIG_PTHREAD_IPC=y
|
||||
|
||||
# Clock for time()
|
||||
CONFIG_POSIX_CLOCK=y
|
||||
# POSIX layer: pthreads, clock for time(), and POSIX socket names (socket(),
|
||||
# bind(), ...). On 4.1 and later this one symbol covers all three. Older
|
||||
# releases still want CONFIG_PTHREAD_IPC / CONFIG_POSIX_CLOCK /
|
||||
# CONFIG_NET_SOCKETS_POSIX_NAMES, which were superseded at different points in
|
||||
# the POSIX rework rather than all at once; see posix_legacy.conf, applied by
|
||||
# CMakeLists.txt below 4.1.
|
||||
CONFIG_POSIX_API=y
|
||||
|
||||
# Networking
|
||||
CONFIG_NETWORKING=y
|
||||
|
|
@ -22,7 +24,6 @@ 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
|
||||
|
|
@ -69,8 +70,8 @@ CONFIG_WOLFSSL_HMAC_DRBG_ENABLED=y
|
|||
# FS
|
||||
CONFIG_DISK_ACCESS=y
|
||||
CONFIG_DISK_DRIVERS=y
|
||||
# RAM disk size moved to devicetree (see ramdisk.overlay) on Zephyr >= 3.5
|
||||
CONFIG_DISK_DRIVER_RAM=y
|
||||
CONFIG_DISK_RAM_VOLUME_SIZE=64
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_MKFS=y
|
||||
CONFIG_FAT_FILESYSTEM_ELM=y
|
||||
|
|
|
|||
|
|
@ -9,11 +9,13 @@ CONFIG_WOLFSSH=y
|
|||
CONFIG_WOLFSSH_SETTINGS_FILE="samples/tests/wolfssh_user_settings_kbi.h"
|
||||
CONFIG_WOLFSSH_SFTP_DEFAULT_DIR="/RAM:"
|
||||
|
||||
# Pthreads
|
||||
CONFIG_PTHREAD_IPC=y
|
||||
|
||||
# Clock for time()
|
||||
CONFIG_POSIX_CLOCK=y
|
||||
# POSIX layer: pthreads, clock for time(), and POSIX socket names (socket(),
|
||||
# bind(), ...). On 4.1 and later this one symbol covers all three. Older
|
||||
# releases still want CONFIG_PTHREAD_IPC / CONFIG_POSIX_CLOCK /
|
||||
# CONFIG_NET_SOCKETS_POSIX_NAMES, which were superseded at different points in
|
||||
# the POSIX rework rather than all at once; see posix_legacy.conf, applied by
|
||||
# CMakeLists.txt below 4.1.
|
||||
CONFIG_POSIX_API=y
|
||||
|
||||
# Networking
|
||||
CONFIG_NETWORKING=y
|
||||
|
|
@ -22,7 +24,6 @@ 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
|
||||
|
|
@ -69,8 +70,8 @@ CONFIG_WOLFSSL_HMAC_DRBG_ENABLED=y
|
|||
# FS
|
||||
CONFIG_DISK_ACCESS=y
|
||||
CONFIG_DISK_DRIVERS=y
|
||||
# RAM disk size moved to devicetree (see ramdisk.overlay) on Zephyr >= 3.5
|
||||
CONFIG_DISK_DRIVER_RAM=y
|
||||
CONFIG_DISK_RAM_VOLUME_SIZE=64
|
||||
CONFIG_FILE_SYSTEM=y
|
||||
CONFIG_FILE_SYSTEM_MKFS=y
|
||||
CONFIG_FAT_FILESYSTEM_ELM=y
|
||||
|
|
|
|||
|
|
@ -8,11 +8,13 @@ CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=131072
|
|||
CONFIG_WOLFSSH=y
|
||||
CONFIG_WOLFSSH_SETTINGS_FILE="samples/tests/wolfssh_user_settings_nofs.h"
|
||||
|
||||
# Pthreads
|
||||
CONFIG_PTHREAD_IPC=y
|
||||
|
||||
# Clock for time()
|
||||
CONFIG_POSIX_CLOCK=y
|
||||
# POSIX layer: pthreads, clock for time(), and POSIX socket names (socket(),
|
||||
# bind(), ...). On 4.1 and later this one symbol covers all three. Older
|
||||
# releases still want CONFIG_PTHREAD_IPC / CONFIG_POSIX_CLOCK /
|
||||
# CONFIG_NET_SOCKETS_POSIX_NAMES, which were superseded at different points in
|
||||
# the POSIX rework rather than all at once; see posix_legacy.conf, applied by
|
||||
# CMakeLists.txt below 4.1.
|
||||
CONFIG_POSIX_API=y
|
||||
|
||||
# Networking
|
||||
CONFIG_NETWORKING=y
|
||||
|
|
@ -21,7 +23,6 @@ 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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
/* RAM disk for the SFTP tests (Zephyr >= 3.5, devicetree). disk-name matches
|
||||
* CONFIG_WOLFSSH_SFTP_DEFAULT_DIR "/RAM:" in prj.conf; 128 * 512 = 64 KiB. */
|
||||
/ {
|
||||
ramdisk0 {
|
||||
compatible = "zephyr,ram-disk";
|
||||
disk-name = "RAM";
|
||||
sector-size = <512>;
|
||||
sector-count = <128>;
|
||||
};
|
||||
};
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Pre-3.5: RAM disk size via Kconfig, not the ramdisk.overlay devicetree node.
|
||||
# 64 KiB = the overlay's 128 sectors * 512 bytes.
|
||||
CONFIG_DISK_RAM_VOLUME_SIZE=64
|
||||
Loading…
Reference in New Issue