cleanup netconfig

This commit is contained in:
Heinz Junkes
2020-09-26 21:45:00 +02:00
committed by Brendan Chandler
parent a718357211
commit 97ce6aecc7
15 changed files with 59 additions and 752 deletions
+3 -4
View File
@@ -25,11 +25,7 @@ rtems_init_CPPFLAGS += -DQEMU_FIXUPS
endif
rtemsCom_SRCS += rtems_init.c
rtemsCom_SRCS += rtems_config.c
ifeq ($(RTEMS_HAS_NETWORKING), yes)
rtemsCom_SRCS += rtems_netconfig.c
else
rtemsCom_SRCS += libbsd_netconfig.c
endif
rtemsCom_SRCS += rtems_util.c
rtemsCom_SRCS += setBootConfigFromNVRAM.c
rtemsCom_SRCS += epicsRtemsInitHookPre.c
@@ -40,6 +36,9 @@ rtemsCom_SRCS += epicsNtp.c
ifeq ($(RTEMS_TARGET_CPU),i386)
rtemsCom_SRCS += ne2kpci.c
endif
ifeq ($(RTEMS_BSP),pc686)
rtemsCom_SRCS += ne2kpci.c
endif
LIBRARY_RTEMS = rtemsCom
@@ -10,9 +10,10 @@
* Dummy version -- use if application does not provide its own version
*/
#include "epicsRtemsInitHooks.h"
#ifdef RTEMS_LEGACY_STACK
int
epicsRtemsInitPostSetBootConfigFromNVRAM(struct rtems_bsdnet_config *config)
{
return 0;
}
#endif
+2 -1
View File
@@ -10,9 +10,10 @@
* Dummy version -- use if application does not provide its own version
*/
#include "epicsRtemsInitHooks.h"
#ifdef RTEMS_LEGACY_STACK
int
epicsRtemsInitPreSetBootConfigFromNVRAM(struct rtems_bsdnet_config *config)
{
return 0;
}
#endif
@@ -10,7 +10,9 @@
* Hooks into RTEMS startup code
*/
#include <bsp.h>
#ifdef RTEMS_LEGACY_STACK
#include <rtems/rtems_bsdnet.h>
#endif
extern char *env_nfsServer;
extern char *env_nfsPath;
@@ -23,8 +25,10 @@ extern "C" {
/*
* Return 0 for success, non-zero for failure (will cause panic)
*/
#ifdef RTEMS_LEGACY_STACK
int epicsRtemsInitPreSetBootConfigFromNVRAM(struct rtems_bsdnet_config *config);
int epicsRtemsInitPostSetBootConfigFromNVRAM(struct rtems_bsdnet_config *config);
#endif
/* Return 0 if local file system was setup, or non-zero (will fall back to network */
int epicsRtemsMountLocalFilesystem(char **argv);
@@ -1,18 +0,0 @@
/*************************************************************************\
* Copyright (c) 2006 The University of Chicago, as Operator of Argonne
* National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Dummy version -- use if application does not provide its own version
*/
#include "epicsRtemsInitHooks.h"
int
epicsRtemsInitPostSetBootConfigFromNVRAM(struct rtems_bsdnet_config *config)
{
return 0;
}
@@ -1,18 +0,0 @@
/*************************************************************************\
* Copyright (c) 2006 The University of Chicago, as Operator of Argonne
* National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Dummy version -- use if application does not provide its own version
*/
#include "epicsRtemsInitHooks.h"
int
epicsRtemsInitPreSetBootConfigFromNVRAM(struct rtems_bsdnet_config *config)
{
return 0;
}
@@ -1,24 +0,0 @@
/*************************************************************************\
* Copyright (c) 2006 The University of Chicago, as Operator of Argonne
* National Laboratory.
* EPICS BASE Versions 3.13.7
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* Hooks into RTEMS startup code
*/
#include <bsp.h>
extern char *env_nfsServer;
extern char *env_nfsPath;
extern char *env_nfsMountPoint;
/*
* Return 0 for success, non-zero for failure (will cause panic)
*/
int epicsRtemsInitPreSetBootConfigFromNVRAM(struct rtems_bsdnet_config *config);
int epicsRtemsInitPostSetBootConfigFromNVRAM(struct rtems_bsdnet_config *config);
/* Return 0 if local file system was setup, or non-zero (will fall back to network */
int epicsRtemsMountLocalFilesystem(char **argv);
@@ -1,116 +0,0 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Saskatchewan
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* RTEMS network configuration for EPICS
* Author: W. Eric Norum
* eric.norum@usask.ca
* (306) 966-5394
*
* This file can be copied to an application source dirctory
* and modified to override the values shown below.
*/
#include <sys/param.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sysexits.h>
#include <unistd.h>
#include <bsp.h>
#include <machine/rtems-bsd-commands.h>
#include <machine/rtems-bsd-rc-conf.h>
#include <machine/rtems-bsd-rc-conf-services.h>
#include "libbsd_netconfig.h"
#include <rtems/console.h>
#include <rtems/shell.h>
#define IFACE_IPV4_DHCP(iface) \
"ifconfig_" # iface "=\"SYNCDHCP\"\n"
#define IFACE_IPV4(iface, addr) \
"ifconfig_" # iface "=\"inet " # addr " netmask 255.255.255.0\"\n"
static const char* rc_conf_text = \
"\n" \
"syslog_priority=\"debug\"\n" \
"\n" \
"#create_args_myvlan=\"vlan 102\"\n" \
"#create_args_yourvlan=\"vlan 202\"\n" \
IFACE_IPV4_DHCP(cgem0) \
"\n" \
"dhcpcd_priority=\"100\"\n" \
"\n" \
"#defaultrouter=\"" NET_CFG_GATEWAY_IP "\"\n" \
"defaultroute_delay=\"5\"\n" \
"\n" \
"#telnetd_enable=\"YES\"\n" \
"#telnetd_options=\"-C 2 -P 100 \"\n" \
"\n" \
"#ftpd_enable=\"YES\"\n" \
"#ftpd_options=\"-v -p 21 -C 2 -P 150 -L -I 10 -R /\"\n" \
"\n" \
"#pf_enable=\"YES\"\n" \
"#pf_rules=\"/etc/mypf.conf\"\n" \
"#pf_flags=\"-q -z\"\n" \
"\n";
static const char* dhcpcd_conf_text = \
"\n" \
"clientid RTEMS test client\n" \
"\n" \
"nodhcp6\n" \
"ipv4only\n" \
"option ntp_servers\n" \
"option rtems_cmdline\n";
int
epicsRtemsPrepareAndRunRCConfFile(void)
{
size_t len;
size_t written;
int fd;
int rv;
struct stat sb;
mkdir("/etc", S_IRWXU | S_IRWXG | S_IRWXO); /* ignore errors, check the dir after. */
assert(stat("/etc", &sb) == 0);
assert(S_ISDIR(sb.st_mode));
printf("--------------- dhcpcd.conf -----------------\n");
printf(dhcpcd_conf_text);
printf("-----------------------------------------\n");
len = strlen(dhcpcd_conf_text);
fd = open("/etc/dhcpcd.conf", O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
assert(fd != -1);
written = write(fd, dhcpcd_conf_text, len);
assert(written == len);
rv = close(fd);
assert(rv == 0);
printf("--------------- rc.conf -----------------\n");
printf(rc_conf_text);
printf("-----------------------------------------\n");
len = strlen(rc_conf_text);
fd = open("/etc/rc.conf", O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
assert(fd != -1);
written = write(fd, rc_conf_text, len);
assert(written == len);
rv = close(fd);
assert(rv == 0);
return (rtems_bsd_run_etc_rc_conf(20, true));
}
@@ -1,24 +0,0 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Saskatchewan
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* RTEMS network configuration header for EPICS
*
* This file can be copied to an application source dirctory
* and modified to override the values shown below.
*/
#include <stdio.h>
#include <bsp.h>
#define NET_CFG_INTERFACE_0 "cgem0"
#define DEFAULT_NETWORK_DHCPCD_ENABLE
#define DEFAULT_NETWORK_NO_INTERFACE_0
// Tests
#define NET_CFG_SELF_IP "141.14.128.89"
#define NET_CFG_NETMASK "255.255.240.0"
#define NET_CFG_GATEWAY_IP "141.14.128.128"
int epicsRtemsPrepareAndRunRCConfFile(void);
@@ -73,12 +73,10 @@ extern void *POSIX_Init(void *argument);
#define CONFIGURE_STACK_CHECKER_ENABLED
//#if __RTEMS_MAJOR__ > 4
#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE (64 * 1024)
#define CONFIGURE_BDBUF_MAX_READ_AHEAD_BLOCKS 4
#define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (1 * 1024 * 1024)
//#endif
/* we are using POSIX_INIT needed by V4
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+28 -44
View File
@@ -57,7 +57,6 @@
#include <rtems/bsd/bsd.h>
#include <rtems/bsd/modules.h>
#include <rtems/dhcpcd.h>
#include "libbsd_netconfig.h"
#include <machine/rtems-bsd-commands.h>
#endif
@@ -102,7 +101,7 @@ char *rtems_bsdnet_bootp_server_name = bootp_server_name_init;
char bootp_boot_file_name_init[128] = "/Volumes/Epics/myExample/bin/RTEMS-qoriq_e500/myExample.boot";
char *rtems_bsdnet_bootp_boot_file_name = bootp_boot_file_name_init;
char bootp_cmdline_init[128] = "/Volumes/Epics/myExample/iocBoot/iocmyExample/st.cmd";
char *rtems_bsdnet_bootp_cmdline = bootp_cmdline_init;
char *rtems_bootp_cmdline = bootp_cmdline_init;
#endif // not LEGACY Stack
int osdNTPGet(struct timespec *now)
@@ -230,9 +229,11 @@ epicsRtemsMountLocalFilesystem(char **argv)
static int
initialize_local_filesystem(char **argv)
{
/*
extern char _DownloadLocation[] __attribute__((weak));
extern char _FlashBase[] __attribute__((weak));
extern char _FlashSize[] __attribute__((weak));
*/
argv[0] = rtems_bsdnet_bootp_boot_file_name;
if (epicsRtemsMountLocalFilesystem(argv)==0) {
@@ -250,13 +251,13 @@ initialize_local_filesystem(char **argv)
printf("Can't unpack tar filesystem\n");
return 0;
}
if ((fd = open(rtems_bsdnet_bootp_cmdline, 0)) >= 0) {
if ((fd = open(rtems_bootp_cmdline, 0)) >= 0) {
close(fd);
printf ("***** Found startup script (%s) in IMFS *****\n", rtems_bsdnet_bootp_cmdline);
argv[1] = rtems_bsdnet_bootp_cmdline;
printf ("***** Found startup script (%s) in IMFS *****\n", rtems_bootp_cmdline);
argv[1] = rtems_bootp_cmdline;
return 1;
}
printf ("***** Startup script (%s) not in IMFS *****\n", rtems_bsdnet_bootp_cmdline);
printf ("***** Startup script (%s) not in IMFS *****\n", rtems_bootp_cmdline);
}
} */
return 0;
@@ -335,7 +336,7 @@ initialize_remote_filesystem(char **argv, int hasLocalFilesystem)
mount_point, strerror(errno));
*cp = '/';
}
argv[1] = rtems_bsdnet_bootp_cmdline;
argv[1] = rtems_bootp_cmdline;
}
else if (hasLocalFilesystem) {
return;
@@ -347,23 +348,22 @@ initialize_remote_filesystem(char **argv, int hasLocalFilesystem)
* if the pathname does not begin with a '/'. This allows
* NFS and TFTP to have a similar view of the remote system.
*/
if (rtems_bsdnet_bootp_cmdline[0] == '/')
cp = rtems_bsdnet_bootp_cmdline + 1;
if (rtems_bootp_cmdline[0] == '/')
cp = rtems_bootp_cmdline + 1;
else
cp = rtems_bsdnet_bootp_cmdline;
cp = rtems_bootp_cmdline;
cp = strchr(cp, '/');
if ((cp == NULL)
|| ((l = cp - rtems_bsdnet_bootp_cmdline) == 0))
LogFatal("\"%s\" is not a valid command pathname.\n", rtems_bsdnet_bootp_cmdline);
|| ((l = cp - rtems_bootp_cmdline) == 0))
LogFatal("\"%s\" is not a valid command pathname.\n", rtems_bootp_cmdline);
cp = mustMalloc(l + 20, "NFS mount paths");
server_path = cp;
printf( " rtems_bootp_server_name: %s\n",rtems_bsdnet_bootp_server_name);
server_name = rtems_bsdnet_bootp_server_name;
if (rtems_bsdnet_bootp_cmdline[0] == '/') {
if (rtems_bootp_cmdline[0] == '/') {
mount_point = server_path;
strncpy(mount_point, rtems_bsdnet_bootp_cmdline, l);
strncpy(mount_point, rtems_bootp_cmdline, l);
mount_point[l] = '\0';
argv[1] = rtems_bsdnet_bootp_cmdline;
argv[1] = rtems_bootp_cmdline;
/*
* Its probably common to embed the mount point in the server
* name so, when this is occurring, dont clobber the mount point
@@ -400,14 +400,14 @@ printf( " rtems_bootp_server_name: %s\n",rtems_bsdnet_bootp_server_name);
}
}
else {
char *abspath = mustMalloc(strlen(rtems_bsdnet_bootp_cmdline)+2,"Absolute command path");
char *abspath = mustMalloc(strlen(rtems_bootp_cmdline)+2,"Absolute command path");
strcpy(server_path, "/tftpboot/");
mount_point = server_path + strlen(server_path);
strncpy(mount_point, rtems_bsdnet_bootp_cmdline, l);
strncpy(mount_point, rtems_bootp_cmdline, l);
mount_point[l] = '\0';
mount_point--;
strcpy(abspath, "/");
strcat(abspath, rtems_bsdnet_bootp_cmdline);
strcat(abspath, rtems_bootp_cmdline);
argv[1] = abspath;
}
}
@@ -689,7 +689,7 @@ dhcpcd_hook_handler(rtems_dhcpcd_hook *hook, char *const *env)
(void)hook;
char ifnamebuf[IF_NAMESIZE];
*ifnamebuf = getPrimaryNetworkInterface();
sprintf(ifnamebuf, "%s", getPrimaryNetworkInterface());
while (*env != NULL) {
name = strtok(*env,"=");
@@ -719,8 +719,8 @@ dhcpcd_hook_handler(rtems_dhcpcd_hook *hook, char *const *env)
}
if(!strncmp(name, "new_rtems_cmdline", 20)){
//printf(" new_rtems_cmdline : %s\n", value);
strncpy(rtems_bsdnet_bootp_cmdline,value, sizeof(bootp_cmdline_init));
printf(" rtems_bsdnet_bootp_cmdline : %s\n", rtems_bsdnet_bootp_cmdline);
strncpy(rtems_bootp_cmdline,value, sizeof(bootp_cmdline_init));
printf(" rtems_bootp_cmdline : %s\n", rtems_bootp_cmdline);
}
// printf("---> %s = %s\n", name, value);
}
@@ -822,7 +822,8 @@ POSIX_Init (void *argument)
// set time to 14.4.2014
now.tv_sec = 1397460606;
now.tv_nsec = 0;
if (clock_settime(CLOCK_REALTIME, &now) < 0)
sc = clock_settime(CLOCK_REALTIME, &now);
if (sc < 0)
printf ("***** Can't set time: %s\n", rtems_status_text (sc));
}
if ( clock_gettime( CLOCK_REALTIME, &now) < 0) {
@@ -839,6 +840,8 @@ POSIX_Init (void *argument)
/* TBD ...
* Architecture-specific hooks
*/
#ifdef RTEMS_LEGACY_STACK
if (epicsRtemsInitPreSetBootConfigFromNVRAM(&rtems_bsdnet_config) != 0)
delayedPanic("epicsRtemsInitPreSetBootConfigFromNVRAM");
if (rtems_bsdnet_config.bootp == NULL) {
@@ -848,8 +851,7 @@ POSIX_Init (void *argument)
if (epicsRtemsInitPostSetBootConfigFromNVRAM(&rtems_bsdnet_config) != 0)
delayedPanic("epicsRtemsInitPostSetBootConfigFromNVRAM");
*/
#endif
/*
* Override RTEMS Posix configuration, it gets started with posix prio 2
*/
@@ -904,9 +906,6 @@ POSIX_Init (void *argument)
dhcpDone = epicsEventMustCreate(epicsEventEmpty);
rtems_dhcpcd_add_hook(&dhcpcd_hook);
/* use /etc/rc.conf, /etc/dhclient.conf ... */
//epicsRtemsPrepareAndRunRCConfFile();
// wait for dhcp done ... should be if SYNCDHCP is used
epicsEventWaitStatus stat;
int counter = 10;
@@ -1027,6 +1026,7 @@ void bsp_predriver_hook(void)
Console_Port_Minor = BSP_CONSOLE_PORT_COM1;
#else
BSPConsolePort = BSP_CONSOLE_PORT_COM1;
#endif
BSPPrintkPort = BSP_CONSOLE_PORT_COM1;
}
@@ -1044,19 +1044,3 @@ void bsp_cleanup(void)
#endif /* QEMU_FIXUPS */
int cexpdebug __attribute__((weak));
/* defines in rtems_config.c
#define CONFIGURE_SHELL_COMMANDS_INIT
#define CONFIGURE_SHELL_COMMANDS_ALL
// exclude commands which won't work right with our configuration
#define CONFIGURE_SHELL_NO_COMMAND_EXIT
#define CONFIGURE_SHELL_NO_COMMAND_LOGOFF
// exclude commands which unnecessarily pull in block driver
#define CONFIGURE_SHELL_NO_COMMAND_MSDOSFMT
#define CONFIGURE_SHELL_NO_COMMAND_BLKSYNC
#define CONFIGURE_SHELL_NO_COMMAND_MKRFS
#define CONFIGURE_SHELL_NO_COMMAND_DEBUGRFS
#define CONFIGURE_SHELL_NO_COMMAND_FDISK
#include <rtems/shellconfig.h>
*/
@@ -1,124 +0,0 @@
/*************************************************************************\
* Copyright (c) 2002 The University of Saskatchewan
* SPDX-License-Identifier: EPICS
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/*
* RTEMS network configuration for EPICS
* Author: W. Eric Norum
* eric.norum@usask.ca
* (306) 966-5394
*
* This file can be copied to an application source dirctory
* and modified to override the values shown below.
*/
#include <stdio.h>
#include <bsp.h>
#include <rtems/rtems_bsdnet.h>
extern void rtems_bsdnet_loopattach();
static struct rtems_bsdnet_ifconfig loopback_config = {
"lo0", /* name */
(int (*)(struct rtems_bsdnet_ifconfig *, int))rtems_bsdnet_loopattach, /* attach function */
NULL, /* link to next interface */
"127.0.0.1", /* IP address */
"255.0.0.0", /* IP net mask */
};
/*
* The following conditionals select the network interface card.
*
* On RTEMS-pc386 targets all network drivers which support run-time
* probing are linked.
* On other targets the network interface specified by the board-support
* package is used.
* To use a different NIC for a particular application, copy this file to the
* application directory and make the appropriate changes.
*/
#if defined(__i386__)
/* no more support for ne2kpci_driver ? */
extern int rtems_fxp_attach (struct rtems_bsdnet_ifconfig *, int);
static struct rtems_bsdnet_ifconfig fxp_driver_config = {
"fxp1", /* name */
rtems_fxp_attach, /* attach function */
&loopback_config, /* link to next interface */
};
extern int rtems_3c509_driver_attach (struct rtems_bsdnet_ifconfig *, int);
static struct rtems_bsdnet_ifconfig e3c509_driver_config = {
"ep0", /* name */
rtems_3c509_driver_attach, /* attach function */
&fxp_driver_config, /* link to next interface */
};
#define FIRST_DRIVER_CONFIG &e3c509_driver_config
#else
# if defined(__PPC)
/*
* FIXME: This really belongs in the BSP
*/
# ifndef RTEMS_BSP_NETWORK_DRIVER_NAME
# define RTEMS_BSP_NETWORK_DRIVER_NAME "dc1"
# endif
# ifndef RTEMS_BSP_NETWORK_DRIVER_ATTACH
# define RTEMS_BSP_NETWORK_DRIVER_ATTACH rtems_dec21140_driver_attach
extern int rtems_dec21140_driver_attach();
# endif
# endif
static struct rtems_bsdnet_ifconfig bsp_driver_config = {
RTEMS_BSP_NETWORK_DRIVER_NAME, /* name */
RTEMS_BSP_NETWORK_DRIVER_ATTACH, /* attach function */
&loopback_config, /* link to next interface */
};
#define FIRST_DRIVER_CONFIG &bsp_driver_config
#endif
/*
* Allow configure/os/CONFIG_SITE.Common.RTEMS to provide domain name
*/
#ifdef RTEMS_NETWORK_CONFIG_DNS_DOMAINNAME
# define XSTR(x) STR(x)
# define STR(x) #x
# define MY_DOMAINNAME XSTR(RTEMS_NETWORK_CONFIG_DNS_DOMAINNAME)
#else
# define MY_DOMAINNAME NULL
#endif
/*
* Allow non-BOOTP network configuration
*/
#ifndef MY_DO_BOOTP
# define MY_DO_BOOTP rtems_bsdnet_do_bootp
#endif
/*
* Allow site- and BSP-specific network buffer space configuration.
* The macro values are specified in KBytes.
*/
#ifndef RTEMS_NETWORK_CONFIG_MBUF_SPACE
# define RTEMS_NETWORK_CONFIG_MBUF_SPACE 180
#endif
#ifndef RTEMS_NETWORK_CONFIG_CLUSTER_SPACE
# define RTEMS_NETWORK_CONFIG_CLUSTER_SPACE 350
#endif
/*
* Network configuration
*/
struct rtems_bsdnet_config rtems_bsdnet_config = {
FIRST_DRIVER_CONFIG, /* Link to next interface */
MY_DO_BOOTP, /* How to find network config */
10, /* If 0 then the network daemons will run at a */
/* priority just less than the lowest-priority */
/* EPICS scan thread. */
/* If non-zero then the network daemons will run */
/* at this *RTEMS* priority */
RTEMS_NETWORK_CONFIG_MBUF_SPACE*1024,
RTEMS_NETWORK_CONFIG_CLUSTER_SPACE*1024,
NULL, /* Host name */
MY_DOMAINNAME, /* Domain name */
};
@@ -1,369 +0,0 @@
/*************************************************************************\
* Copyright (c) 2008 UChicago Argonne LLC, as Operator of Argonne
* National Laboratory.
* EPICS BASE is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <fcntl.h>
#include <unistd.h>
#include <bsp.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <epicsStdlib.h>
#include <epicsStdio.h>
#include <epicsString.h>
#include <envDefs.h>
char *env_nfsServer;
char *env_nfsPath;
char *env_nfsMountPoint;
/*
* Split argument string of form nfs_server:nfs_export:<path>
* The nfs_export component will be used as:
* - the path to the directory exported from the NFS server
* - the local mount point
* - a prefix of <path>
* For example, the argument string:
* romeo:/export/users:smith/ioc/iocexample/st.cmd
* would:
* - mount /export/users from NFS server romeo on /export/users
* - chdir to /export/users/smith/ioc/iocexample
* - read commands from st.cmd
*/
static void
splitRtemsBsdnetBootpCmdline(void)
{
char *cp1, *cp2, *cp3;
if ((cp1 = rtems_bsdnet_bootp_cmdline) == NULL)
return;
if (((cp2 = strchr(cp1, ':')) != NULL)
&& (((cp3 = strchr(cp2+1, ' ')) != NULL)
|| ((cp3 = strchr(cp2+1, ':')) != NULL))) {
int l1 = cp2 - cp1;
int l2 = cp3 - cp2 - 1;
int l3 = strlen(cp3) - 1;
if (l1 && l2 && l3) {
*cp2++ = '\0';
*cp3 = '\0';
env_nfsServer = cp1;
env_nfsMountPoint = env_nfsPath = epicsStrDup(cp2);
*cp3 = '/';
rtems_bsdnet_bootp_cmdline = cp2;
}
}
}
/*
* Split NFS mount information of the form nfs_server:host_path:local_path
*/
static void
splitNfsMountPath(char *nfsString)
{
char *cp2, *cp3;
if (nfsString == NULL)
return;
if (((cp2 = strchr(nfsString, ':')) != NULL)
&& (((cp3 = strchr(cp2+1, ' ')) != NULL)
|| ((cp3 = strchr(cp2+1, ':')) != NULL))) {
int l1 = cp2 - nfsString;
int l2 = cp3 - cp2 - 1;
int l3 = strlen(cp3) - 1;
if (l1 && l2 && l3) {
*cp2++ = '\0';
*cp3++ = '\0';
env_nfsServer = nfsString;
env_nfsPath = cp2;
env_nfsMountPoint = cp3;
}
}
}
#if defined(HAVE_MOTLOAD)
/*
* Motorola MOTLOAD NVRAM Access
*/
static char *
gev(const char *parm, volatile char *nvp)
{
const char *val;
const char *name;
char *ret;
char c;
for (;;) {
if (*nvp == '\0')
return NULL;
name = parm;
while ((c = *nvp++) != '\0') {
if ((c == '=') && (*name == '\0')) {
val = (char *)nvp;
while (*nvp++ != '\0')
continue;
ret = malloc(nvp - val);
if (ret == NULL)
return NULL;
strcpy(ret, val);
return ret;
}
if (c != *name++) {
while (*nvp++ != '\0')
continue;
break;
}
}
}
}
static char *
motScriptParm(const char *mot_script_boot, char parm)
{
const char *cp;
char *ret;
int l;
while (*mot_script_boot != '\0') {
if (isspace(*(unsigned char *)mot_script_boot)
&& (*(mot_script_boot+1) == '-')
&& (*(mot_script_boot+2) == parm)) {
mot_script_boot += 3;
cp = mot_script_boot;
while ((*mot_script_boot != '\0') &&
!isspace(*(unsigned char *)mot_script_boot))
mot_script_boot++;
l = mot_script_boot - cp;
ret = malloc(l+1);
if (ret == NULL)
return NULL;
strncpy(ret, cp, l);
*(ret+l) = '\0';
return ret;
}
mot_script_boot++;
}
return NULL;
}
void
setBootConfigFromNVRAM(void)
{
char *cp;
const char *mot_script_boot;
char *nvp;
# if defined(BSP_NVRAM_BASE_ADDR)
nvp = (volatile unsigned char *)(BSP_NVRAM_BASE_ADDR+0x70f8);
# elif defined(BSP_I2C_VPD_EEPROM_DEV_NAME)
char gev_buf[3592];
int fd;
if ((fd = open(BSP_I2C_VPD_EEPROM_DEV_NAME, 0)) < 0) {
printf("Can't open %s: %s\n", BSP_I2C_VPD_EEPROM_DEV_NAME, strerror(errno));
return;
}
lseek(fd, 0x10f8, SEEK_SET);
if (read(fd, gev_buf, sizeof gev_buf) != sizeof gev_buf) {
printf("Can't read %s: %s\n", BSP_I2C_VPD_EEPROM_DEV_NAME, strerror(errno));
return;
}
close(fd);
nvp = gev_buf;
# else
# error "No way to read GEV!"
# endif
if (rtems_bsdnet_config.bootp != NULL)
return;
mot_script_boot = gev("mot-script-boot", nvp);
if ((rtems_bsdnet_bootp_server_name = gev("mot-/dev/enet0-sipa", nvp)) == NULL)
rtems_bsdnet_bootp_server_name = motScriptParm(mot_script_boot, 's');
if ((rtems_bsdnet_config.gateway = gev("mot-/dev/enet0-gipa", nvp)) == NULL)
rtems_bsdnet_config.gateway = motScriptParm(mot_script_boot, 'g');
if ((rtems_bsdnet_config.ifconfig->ip_netmask = gev("mot-/dev/enet0-snma", nvp)) == NULL)
rtems_bsdnet_config.ifconfig->ip_netmask = motScriptParm(mot_script_boot, 'm');
rtems_bsdnet_config.name_server[0] = gev("rtems-dns-server", nvp);
if (rtems_bsdnet_config.name_server[0] == NULL)
rtems_bsdnet_config.name_server[0] = rtems_bsdnet_bootp_server_name;
cp = gev("rtems-dns-domainname", nvp);
if (cp)
rtems_bsdnet_config.domainname = cp;
if ((rtems_bsdnet_config.ifconfig->ip_address = gev("mot-/dev/enet0-cipa", nvp)) == NULL)
rtems_bsdnet_config.ifconfig->ip_address = motScriptParm(mot_script_boot, 'c');
rtems_bsdnet_config.hostname = gev("rtems-client-name", nvp);
if (rtems_bsdnet_config.hostname == NULL)
rtems_bsdnet_config.hostname = rtems_bsdnet_config.ifconfig->ip_address;
if ((rtems_bsdnet_bootp_boot_file_name = gev("mot-/dev/enet0-file", nvp)) == NULL)
rtems_bsdnet_bootp_boot_file_name = motScriptParm(mot_script_boot, 'f');
rtems_bsdnet_bootp_cmdline = gev("epics-script", nvp);
splitRtemsBsdnetBootpCmdline();
splitNfsMountPath(gev("epics-nfsmount", nvp));
rtems_bsdnet_config.ntp_server[0] = gev("epics-ntpserver", nvp);
if (rtems_bsdnet_config.ntp_server[0] == NULL)
rtems_bsdnet_config.ntp_server[0] = rtems_bsdnet_bootp_server_name;
if ((cp = gev("epics-tz", nvp)) != NULL)
epicsEnvSet("TZ", cp);
}
#elif defined(HAVE_PPCBUG)
/*
* Motorola PPCBUG NVRAM Access
*/
struct ppcbug_nvram {
uint32_t PacketVersionIdentifier;
uint32_t NodeControlMemoryAddress;
uint32_t BootFileLoadAddress;
uint32_t BootFileExecutionAddress;
uint32_t BootFileExecutionDelay;
uint32_t BootFileLength;
uint32_t BootFileByteOffset;
uint32_t TraceBufferAddress;
uint32_t ClientIPAddress;
uint32_t ServerIPAddress;
uint32_t SubnetIPAddressMask;
uint32_t BroadcastIPAddressMask;
uint32_t GatewayIPAddress;
uint8_t BootpRarpRetry;
uint8_t TftpRarpRetry;
uint8_t BootpRarpControl;
uint8_t UpdateControl;
char BootFilenameString[64];
char ArgumentFilenameString[64];
};
static char *addr(char *cbuf, uint32_t addr)
{
struct in_addr a;
if ((a.s_addr = addr) == 0)
return NULL;
return (char *)inet_ntop(AF_INET, &a, cbuf, INET_ADDRSTRLEN);
}
void
setBootConfigFromNVRAM(void)
{
static struct ppcbug_nvram nvram;
static char ip_address[INET_ADDRSTRLEN];
static char ip_netmask[INET_ADDRSTRLEN];
static char server[INET_ADDRSTRLEN];
static char gateway[INET_ADDRSTRLEN];
if (rtems_bsdnet_config.bootp != NULL)
return;
/*
* Get network configuation from PPCBUG.
* The 'correct' way to do this would be to issue a .NETCFIG PPCBUG
* system call. Unfortunately it is very difficult to issue such a
* call once RTEMS is up and running so we just copy from the 'known'
* location of the network configuration parameters.
* Care must be taken to access the NVRAM a byte at a time.
*/
#if defined(NVRAM_INDIRECT)
{
volatile char *addrLo = (volatile char *)0x80000074;
volatile char *addrHi = (volatile char *)0x80000075;
volatile char *data = (volatile char *)0x80000077;
int addr = 0x1000;
char *d = (char *)&nvram;
while (d < ((char *)&nvram + sizeof nvram)) {
*addrLo = addr & 0xFF;
*addrHi = (addr >> 8) & 0xFF;
*d++ = *data;
addr++;
}
}
#else
{
volatile char *s = (volatile char *)0xFFE81000;
char *d = (char *)&nvram;
while (d < ((char *)&nvram + sizeof nvram))
*d++ = *s++;
}
#endif
/*
* Assume that the boot server is also the name, log and ntp server!
*/
rtems_bsdnet_config.name_server[0] =
rtems_bsdnet_config.ntp_server[0] =
rtems_bsdnet_bootp_server_name = addr(server, nvram.ServerIPAddress);
rtems_bsdnet_bootp_server_address.s_addr = nvram.ServerIPAddress;
/*
* Nothing better to use as host name!
*/
rtems_bsdnet_config.ifconfig->ip_address =
rtems_bsdnet_config.hostname = addr(ip_address, nvram.ClientIPAddress);
rtems_bsdnet_config.gateway = addr(gateway, nvram.GatewayIPAddress);
rtems_bsdnet_config.ifconfig->ip_netmask = addr(ip_netmask, nvram.SubnetIPAddressMask);
rtems_bsdnet_bootp_boot_file_name = nvram.BootFilenameString;
rtems_bsdnet_bootp_cmdline = nvram.ArgumentFilenameString;
splitRtemsBsdnetBootpCmdline();
}
#elif defined(__mcf528x__)
static char *
env(const char *parm, const char *defaultValue)
{
const char *cp = bsp_getbenv(parm);
if (!cp) {
if (!defaultValue)
return NULL;
cp = defaultValue;
printf ("%s environment variable missing -- using %s.\n", parm, cp);
}
return epicsStrDup(cp);
}
void
setBootConfigFromNVRAM(void)
{
const char *cp1;
if (rtems_bsdnet_config.bootp != NULL)
return;
rtems_bsdnet_config.gateway = env("GATEWAY", NULL);
rtems_bsdnet_config.ifconfig->ip_netmask = env("NETMASK", "255.255.252.0");
rtems_bsdnet_bootp_server_name = env("SERVER", "192.168.0.1");
rtems_bsdnet_config.name_server[0] = env("NAMESERVER", rtems_bsdnet_bootp_server_name);
rtems_bsdnet_config.ntp_server[0] = env("NTPSERVER", rtems_bsdnet_bootp_server_name);
cp1 = env("DOMAIN", NULL);
if (cp1 != NULL)
rtems_bsdnet_config.domainname = cp1;
rtems_bsdnet_config.hostname = env("HOSTNAME", "iocNobody");
rtems_bsdnet_config.ifconfig->ip_address = env("IPADDR0", "192.168.0.2");
rtems_bsdnet_bootp_boot_file_name = env("BOOTFILE", "uC5282App.boot");
rtems_bsdnet_bootp_cmdline = env("CMDLINE", "epics/iocBoot/iocNobody/st.cmd");
splitNfsMountPath(env("NFSMOUNT", NULL));
if ((cp1 = env("TZ", NULL)) != NULL)
epicsEnvSet("TZ", cp1);
}
#else
/*
* Placeholder for systems without NVRAM
*/
void
setBootConfigFromNVRAM(void)
{
printf("SYSTEM HAS NO NON-VOLATILE RAM!\n");
printf("YOU MUST USE SOME OTHER METHOD TO OBTAIN NETWORK CONFIGURATION\n");
}
#endif
@@ -15,6 +15,8 @@
*/
#include <stdio.h>
#include <bsp.h>
#ifdef RTEMS_LEGACY_STACK // old non libbsd stack
#include <rtems/rtems_bsdnet.h>
extern void rtems_bsdnet_loopattach();
@@ -37,7 +39,6 @@ static struct rtems_bsdnet_ifconfig loopback_config = {
* application directory and make the appropriate changes.
*/
#if defined(__i386__)
extern int
rtems_ne2kpci_driver_attach (struct rtems_bsdnet_ifconfig *config, int attach);
static struct rtems_bsdnet_ifconfig ne2k_driver_config = {
@@ -45,11 +46,12 @@ static struct rtems_bsdnet_ifconfig ne2k_driver_config = {
rtems_ne2kpci_driver_attach, /* attach function */
&loopback_config, /* link to next interface */
};
extern int rtems_fxp_attach (struct rtems_bsdnet_ifconfig *, int);
static struct rtems_bsdnet_ifconfig fxp_driver_config = {
"fxp1", /* name */
rtems_fxp_attach, /* attach function */
&ne2k_driver_config, /* link to next interface */
&ne2k_driver_config, /* link to next interface */
};
extern int rtems_3c509_driver_attach (struct rtems_bsdnet_ifconfig *, int);
static struct rtems_bsdnet_ifconfig e3c509_driver_config = {
@@ -127,3 +129,11 @@ struct rtems_bsdnet_config rtems_bsdnet_config = {
NULL, /* Host name */
MY_DOMAINNAME, /* Domain name */
};
#else // libbsd "new" stack
// nothing to do??
#endif // RTEMS_LEGACY_STACK
@@ -12,7 +12,9 @@
#include <netinet/in.h>
#include <fcntl.h>
#include <unistd.h>
#ifdef RTEMS_LEGACY_STACK
#include <rtems/rtems_bsdnet.h>
#endif
#include <bsp.h>
#include <string.h>
#include <ctype.h>
@@ -26,6 +28,7 @@ char *env_nfsServer;
char *env_nfsPath;
char *env_nfsMountPoint;
extern char* rtems_bootp_cmdline;
/*
* Split argument string of form nfs_server:nfs_export:<path>
* The nfs_export component will be used as:
@@ -44,7 +47,7 @@ splitRtemsBsdnetBootpCmdline(void)
{
char *cp1, *cp2, *cp3;
if ((cp1 = rtems_bsdnet_bootp_cmdline) == NULL)
if ((cp1 = rtems_bootp_cmdline) == NULL)
return;
if (((cp2 = strchr(cp1, ':')) != NULL)
&& (((cp3 = strchr(cp2+1, ' ')) != NULL)
@@ -58,7 +61,7 @@ splitRtemsBsdnetBootpCmdline(void)
env_nfsServer = cp1;
env_nfsMountPoint = env_nfsPath = epicsStrDup(cp2);
*cp3 = '/';
rtems_bsdnet_bootp_cmdline = cp2;
rtems_bootp_cmdline = cp2;
}
}
}
@@ -207,7 +210,7 @@ setBootConfigFromNVRAM(void)
if ((rtems_bsdnet_bootp_boot_file_name = gev("mot-/dev/enet0-file", nvp)) == NULL)
rtems_bsdnet_bootp_boot_file_name = motScriptParm(mot_script_boot, 'f');
rtems_bsdnet_bootp_cmdline = gev("epics-script", nvp);
rtems_bootp_cmdline = gev("epics-script", nvp);
splitRtemsBsdnetBootpCmdline();
splitNfsMountPath(gev("epics-nfsmount", nvp));
rtems_bsdnet_config.ntp_server[0] = gev("epics-ntpserver", nvp);
@@ -313,7 +316,7 @@ setBootConfigFromNVRAM(void)
rtems_bsdnet_config.ifconfig->ip_netmask = addr(ip_netmask, nvram.SubnetIPAddressMask);
rtems_bsdnet_bootp_boot_file_name = nvram.BootFilenameString;
rtems_bsdnet_bootp_cmdline = nvram.ArgumentFilenameString;
rtems_bootp_cmdline = nvram.ArgumentFilenameString;
splitRtemsBsdnetBootpCmdline();
}
@@ -352,7 +355,7 @@ setBootConfigFromNVRAM(void)
rtems_bsdnet_config.hostname = env("HOSTNAME", "iocNobody");
rtems_bsdnet_config.ifconfig->ip_address = env("IPADDR0", "192.168.0.2");
rtems_bsdnet_bootp_boot_file_name = env("BOOTFILE", "uC5282App.boot");
rtems_bsdnet_bootp_cmdline = env("CMDLINE", "epics/iocBoot/iocNobody/st.cmd");
rtems_bootp_cmdline = env("CMDLINE", "epics/iocBoot/iocNobody/st.cmd");
splitNfsMountPath(env("NFSMOUNT", NULL));
if ((cp1 = env("TZ", NULL)) != NULL)
epicsEnvSet("TZ", cp1);