From 2b8a944a7d9d5dcaafbabf3d0dbf57dab36f926a Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Wed, 12 Apr 2023 14:26:00 -1000 Subject: [PATCH] rtems: Add legacy network support and fix LDFLAGS RTEMS 6 has moved the legacy network support out of the main repo to a 3rd party library. This change adds support for using the legacy networking stack with EPICS in a backwards compatible way. A BSP can be built with libbsd or the legacy stack and by default EPICS 7 assumes libbsd. This patch also fixes the LDFLAGS adding the RTEMS LDFLAGS imported from Makefile.inc. --- configure/os/CONFIG.Common.RTEMS | 48 ++++++++++++++++++++++++++------ configure/toolchain.c | 22 +++++++++++++-- 2 files changed, 59 insertions(+), 11 deletions(-) diff --git a/configure/os/CONFIG.Common.RTEMS b/configure/os/CONFIG.Common.RTEMS index a736addaa..c58ac7bdc 100644 --- a/configure/os/CONFIG.Common.RTEMS +++ b/configure/os/CONFIG.Common.RTEMS @@ -65,7 +65,7 @@ CXXFLAGS = $($(BUILD_CLASS)_CXXFLAGS) $(POSIX_CXXFLAGS) $(OPT_CXXFLAGS)\ $(USR_CXXFLAGS) $(CMD_CXXFLAGS) $(ARCH_DEP_CXXFLAGS) $(CODE_CXXFLAGS)\ $(STATIC_CXXFLAGS) $(OP_SYS_CXXFLAGS) $(LIBRARY_SRC_CFLAGS) -LDFLAGS = $(OPT_LDFLAGS) $(TARGET_LDFLAGS) $(USR_LDFLAGS) $(CMD_LDFLAGS)\ +LDFLAGS += $(OPT_LDFLAGS) $(TARGET_LDFLAGS) $(USR_LDFLAGS) $(CMD_LDFLAGS)\ $(POSIX_LDFLAGS) $(ARCH_DEP_LDFLAGS) $(DEBUG_LDFLAGS) $(OP_SYS_LDFLAGS)\ $($(BUILD_CLASS)_LDFLAGS) $(RUNTIME_LDFLAGS) $(CODE_LDFLAGS) @@ -102,15 +102,47 @@ OS_CLASS = RTEMS # Operating system compile & link flags OP_SYS_CFLAGS += -D__LINUX_ERRNO_EXTENSIONS__ -OP_SYS_CFLAGS_NET_yes = -DRTEMS_LEGACY_STACK -OP_SYS_CFLAGS += $(OP_SYS_CFLAGS_NET_$(RTEMS_HAS_NETWORKING)) - -ifeq ($(RTEMS_HAS_POSIX_API),yes) -POSIX_CPPFLAGS = -D_GNU_SOURCE -D_DEFAULT_SOURCE +# Has RTEMS been built with the internal legacy stack? +ifeq ($(RTEMS_LEGACY_NETWORKING_INTERNAL),yes) +RTEMS_HAS_NETWORKING = yes +RTEMS_NETWORKING = legacy_internal endif -OP_SYS_LDLIBS_posix_NET_yes = -ltftpfs -lnfs -lz -ltelnetd -OP_SYS_LDLIBS_posix_NET_no = -ltftpfs -lbsd -lz +# Has RTEMS been built with the legacy stack as a separate package? +ifeq ($(RTEMS_LEGACY_NETWORKING),yes) +RTEMS_HAS_NETWORKING = yes +RTEMS_NETWORKING = legacy +endif + +# Has RTEMS been built with the libbsd stack as a separate package? +ifeq ($(RTEMS_BSD_NETWORKING),yes) +RTEMS_HAS_NETWORKING = yes +RTEMS_NETWORKING = bsd +endif + +RTEMS_LEGACY_NET_LIB_no= + +# Legacy network with RTEMS 5 and earlier +RTEMS_NET_LIB_legacy_internal=-lnfs +OP_SYS_CFLAGS_NET_legacy_internal = -DRTEMS_LEGACY_STACK + +# Legacy network with RTEMS 6 is a separate package and library +RTEMS_NET_LIB_legacy=-lnfs -lnetworking -lnfs +OP_SYS_CFLAGS_NET_legacy = -DRTEMS_LEGACY_STACK + +# LibBSD network with RTEMS 5 and 6 is a separate package and library +RTEMS_NET_LIB_bsd=-lbsd +OP_SYS_CFLAGS_NET_bsd = -DRTEMS_LIBBSD_STACK + +# Set the networking flags +OP_SYS_CFLAGS += $(OP_SYS_CFLAGS_NET_$(RTEMS_NETWORKING)) + +POSIX_CPPFLAGS_posix = -D_GNU_SOURCE -D_DEFAULT_SOURCE +POSIX_CPPFLAGS = $(POSIX_CPPFLAGS_$(OS_API)) + +OP_SYS_LDLIBS_posix_NET_yes = -ltftpfs -lz -ltelnetd +OP_SYS_LDLIBS_posix_NET_yes += $(RTEMS_NET_LIB_$(RTEMS_NETWORKING)) +OP_SYS_LDLIBS_posix_NET_no = -ltftpfs -lz OP_SYS_LDLIBS_score_NET_yes = -lnfs OP_SYS_LDLIBS_score_NET_no = -lnfs OP_SYS_LDLIBS += -lrtemsCom -lCom diff --git a/configure/toolchain.c b/configure/toolchain.c index 79333198c..af03f5246 100644 --- a/configure/toolchain.c +++ b/configure/toolchain.c @@ -30,9 +30,26 @@ MSVC_VER = _MSC_VER #ifdef __rtems__ #include # if __RTEMS_MAJOR__>=5 -OS_API = posix + OS_API = posix # else -OS_API = score + OS_API = score +# endif +# if defined(RTEMS_NETWORKING) + /* legacy stack circa RTEMS <= 5 and networking internal to RTEMS */ + RTEMS_LEGACY_NETWORKING_INTERNAL = yes +# else +# if !defined(__has_include) + /* assume old GCC implies RTEMS < 5 with mis-configured BSP */ +# error rebuild BSP with --enable-network +# elif __has_include() + /* legacy stack circa RTEMS > 5 */ + RTEMS_LEGACY_NETWORKING = yes +# elif __has_include() + /* libbsd stack */ + RTEMS_BSD_NETWORKING = yes +# else +# error Cannot determine RTEMS network configuration +# endif # endif #endif @@ -51,4 +68,3 @@ COMMANDLINE_LIBRARY ?= $(strip $(if $(wildcard $(if $(GNU_DIR),$(GNU_DIR)/includ #if defined(_FORTIFY_SOURCE) && _FORTIFY_SOURCE>2 OP_SYS_CPPFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 #endif -