diff --git a/documentation/new-notes/PR-853.md b/documentation/new-notes/PR-853.md new file mode 100644 index 000000000..e35c17563 --- /dev/null +++ b/documentation/new-notes/PR-853.md @@ -0,0 +1,17 @@ +### Static network configuration for RTEMS targets using libBSD + +GitHub [PR #853](https://github.com/epics-base/epics-base/pull/853) + +RTEMS targets built against the libBSD network stack can now use a static +network configuration in addition to DHCP. + +When a static IP address and netmask can be read from the board's boot +configuration, the first non-loopback interface is configured with that static +address; otherwise the target falls back to DHCP as before. + +The boot configuration is read using the mechanism appropriate to the board: + + * MOTLOAD boards read the NVRAM Global Environment Variables (GEV), falling + back to the parameters in the `mot-script-boot` boot script. + * PPCBUG boards read their PPCBUG NVRAM. + * ColdFire (`mcf528x`) boards read their bootloader environment variables. diff --git a/modules/libcom/RTEMS/posix/rtems_config.c b/modules/libcom/RTEMS/posix/rtems_config.c index b3c42097f..5b5fe9a6b 100644 --- a/modules/libcom/RTEMS/posix/rtems_config.c +++ b/modules/libcom/RTEMS/posix/rtems_config.c @@ -47,9 +47,7 @@ extern void *POSIX_Init(void *argument); #ifndef RTEMS_LEGACY_STACK #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM -/* - * Configure LibBSD. - */ + //#define RTEMS_BSD_CONFIG_NET_PF_UNIX //#define RTEMS_BSD_CONFIG_NET_IF_BRIDGE //#define RTEMS_BSD_CONFIG_NET_IF_LAGG diff --git a/modules/libcom/RTEMS/posix/rtems_init.c b/modules/libcom/RTEMS/posix/rtems_init.c index e8afba06b..a709f8915 100644 --- a/modules/libcom/RTEMS/posix/rtems_init.c +++ b/modules/libcom/RTEMS/posix/rtems_init.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include #include @@ -65,6 +67,8 @@ #include #include #include +#include +#include #endif #include @@ -873,6 +877,50 @@ default_network_dhcpcd(void) sc = rtems_dhcpcd_start(NULL); assert(sc == RTEMS_SUCCESSFUL); } + +/* + * Block until the named interface reports link up via an RTM_IFINFO routing + * message, or until timeout_secs elapses. + * + * route_sock must already be open (opened before the interface was configured + * so that no RTM_IFINFO event can be missed). + * + * This function was modeled after the RTM_IFINFO handling in + * rtems-libbsd/dhcpcd/if-bsd.c (manage_link). There's a + * simpler implementation in a test that uses a sleep loop in + * rtems-libbsd/testsuite/include/rtems/bsd/test/default-init.h, but + * we chose this more responsive event based implementation. + * + * Returns 0 if link came up, -1 on timeout or error. + */ +static int +wait_for_link_up(int route_sock, const char *ifname, int timeout_secs) +{ + printf("Waiting for link on %s (timeout %ds)...\n", ifname, timeout_secs); + + struct timeval tv = { .tv_sec = timeout_secs, .tv_usec = 0 }; + setsockopt(route_sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); + + char buf[sizeof(struct if_msghdr) + sizeof(struct sockaddr_dl)]; + ssize_t n; + while ((n = recv(route_sock, buf, sizeof(buf), 0)) > 0) { + struct rt_msghdr *rtm = (struct rt_msghdr *)(void *)buf; + if (rtm->rtm_type == RTM_IFINFO) { + struct if_msghdr *ifm = (struct if_msghdr *)(void *)buf; + char name[IFNAMSIZ]; + if (if_indextoname(ifm->ifm_index, name) != NULL && + strcmp(name, ifname) == 0 && + ifm->ifm_data.ifi_link_state == LINK_STATE_UP) { + return 0; + } + } + } + + /* recv returned <= 0: SO_RCVTIMEO expired (EAGAIN) or socket error */ + printf("Warning: link did not come up on %s within %ds\n", + ifname, timeout_secs); + return -1; +} #endif // not RTEMS_LEGACY_STACK #if __RTEMS_MAJOR__>4 @@ -990,8 +1038,8 @@ POSIX_Init ( void *argument __attribute__((unused))) if (epicsRtemsInitPreSetBootConfigFromNVRAM(&rtems_bsdnet_config) != 0) delayedPanic("epicsRtemsInitPreSetBootConfigFromNVRAM"); if (rtems_bsdnet_config.bootp == NULL) { - extern void setBootConfigFromNVRAM(void); - setBootConfigFromNVRAM(); + extern int setBootConfigFromNVRAM(char *, size_t); + setBootConfigFromNVRAM(NULL, 0); } if (epicsRtemsInitPostSetBootConfigFromNVRAM(&rtems_bsdnet_config) != 0) delayedPanic("epicsRtemsInitPostSetBootConfigFromNVRAM"); @@ -1047,41 +1095,75 @@ POSIX_Init ( void *argument __attribute__((unused))) printf("\n***** ifconfig lo0 *****\n"); rtems_bsd_ifconfig_lo0(); - printf("\n***** add dhcpcd hook *****\n"); - dhcpDone = epicsEventMustCreate(epicsEventEmpty); - rtems_dhcpcd_add_hook(&dhcpcd_hook); + /* Check whether global environment static network config exists. + * If so, use that, else, fall back to DHCP. */ + extern int setBootConfigFromNVRAM(char *, size_t); - printf("\n***** Start default network dhcpcd *****\n"); - // if MY_BOOTP??? - default_network_dhcpcd(); + /* Open route socket before configuring the interface so that no + * events are missed. */ + int route_sock = socket(PF_ROUTE, SOCK_RAW, 0); + if (route_sock < 0) + printf("Warning: could not open PF_ROUTE socket: %s\n", strerror(errno)); - /* this seems to be hard coded in the BSP -> Sebastian Huber ? */ - printf("\n--Info (hpj)-- bsd task prio IRQS: %d -----\n", rtems_bsd_get_task_priority("IRQS")); - printf("\n--Info (hpj)-- bsd task prio TIME: %d -----\n", rtems_bsd_get_task_priority("TIME")); + printf("\n***** checking for static network configuration *****\n"); + int status = setBootConfigFromNVRAM(rtemsInit_NTP_server_ip, + sizeof(rtemsInit_NTP_server_ip)); + bool try_dhcp = status != 0; + + if (try_dhcp) { + /* Route socket not needed — DHCP path has its own event mechanism */ + if (route_sock >= 0) { + close(route_sock); + route_sock = -1; + } + + printf("\n***** add dhcpcd hook *****\n"); + dhcpDone = epicsEventMustCreate(epicsEventEmpty); + rtems_dhcpcd_add_hook(&dhcpcd_hook); + + printf("\n***** Start default network dhcpcd *****\n"); + default_network_dhcpcd(); + + /* this seems to be hard coded in the BSP -> Sebastian Huber ? */ + printf("\n--Info (hpj)-- bsd task prio IRQS: %d -----\n", rtems_bsd_get_task_priority("IRQS")); + printf("\n--Info (hpj)-- bsd task prio TIME: %d -----\n", rtems_bsd_get_task_priority("TIME")); - // wait for dhcp done ... should be if SYNCDHCP is used - epicsEventWaitStatus stat; - printf("\n ---- Waiting for DHCP ...\n"); - stat = epicsEventWaitWithTimeout(dhcpDone, 600); - if (stat == epicsEventOK) - epicsEventDestroy(dhcpDone); - else if (stat == epicsEventWaitTimeout) - printf("\n ---- DHCP timed out!\n"); - else - printf("\n ---- dhcpDone Event Unknown state %d\n", stat); + // wait for dhcp done ... should be if SYNCDHCP is used + epicsEventWaitStatus stat; + printf("\n ---- Waiting for DHCP ...\n"); + stat = epicsEventWaitWithTimeout(dhcpDone, 600); + if (stat == epicsEventOK) + epicsEventDestroy(dhcpDone); + else if (stat == epicsEventWaitTimeout) + printf("\n ---- DHCP timed out!\n"); + else + printf("\n ---- dhcpDone Event Unknown state %d\n", stat); + } else { + /* Static IP: block until the physical link comes up before + * proceeding to NTP and NFS, analogous to the DHCP event wait. */ + if (route_sock >= 0) { + char ifnamebuf[IF_NAMESIZE]; + char *ifname = if_indextoname(1, ifnamebuf); + if (ifname != NULL) + wait_for_link_up(route_sock, ifname, 30); + close(route_sock); + } + } - const char* ifconfg_args[] = { - "ifconfig", NULL - }; - const char* netstat_args[] = { - "netstat", "-rn", NULL - }; + { // Dump ifconfig and netstat info to stdout + const char* ifconfg_args[] = { + "ifconfig", NULL + }; + const char* netstat_args[] = { + "netstat", "-rn", NULL + }; - printf("-------------- IFCONFIG -----------------\n"); - rtems_bsd_command_ifconfig(1, (char**) ifconfg_args); - printf("-------------- NETSTAT ------------------\n"); - rtems_bsd_command_netstat(2, (char**) netstat_args); + printf("-------------- IFCONFIG -----------------\n"); + rtems_bsd_command_ifconfig(1, (char**) ifconfg_args); + printf("-------------- NETSTAT ------------------\n"); + rtems_bsd_command_netstat(2, (char**) netstat_args); + } /* until now there is no NTP support in libbsd -> Sebastian Huber ... */ printf("\n***** Until now no NTP support in RTEMS 5 with rtems-libbsd *****\n"); @@ -1159,6 +1241,14 @@ POSIX_Init ( void *argument __attribute__((unused))) // printf (" telnetd initialized with result %d\n", result); #endif +#if 0 +// Start an rtems shell before main, for debugging RTEMS system issues + rtems_shell_init("SHLL", RTEMS_MINIMUM_STACK_SIZE * 4, + 100, "/dev/console", + false, true, + NULL); +#endif + printf ("***** Preparing EPICS application *****\n"); iocshRegisterRTEMS (); set_directory (argv[1]); diff --git a/modules/libcom/RTEMS/score/rtems_init.c b/modules/libcom/RTEMS/score/rtems_init.c index cd8872c4b..77e2e3368 100644 --- a/modules/libcom/RTEMS/score/rtems_init.c +++ b/modules/libcom/RTEMS/score/rtems_init.c @@ -591,8 +591,8 @@ Init (rtems_task_argument ignored) if (epicsRtemsInitPreSetBootConfigFromNVRAM(&rtems_bsdnet_config) != 0) delayedPanic("epicsRtemsInitPreSetBootConfigFromNVRAM"); if (rtems_bsdnet_config.bootp == NULL) { - extern void setBootConfigFromNVRAM(void); - setBootConfigFromNVRAM(); + extern int setBootConfigFromNVRAM(char *, size_t); + setBootConfigFromNVRAM(NULL, 0); } if (epicsRtemsInitPostSetBootConfigFromNVRAM(&rtems_bsdnet_config) != 0) delayedPanic("epicsRtemsInitPostSetBootConfigFromNVRAM"); diff --git a/modules/libcom/RTEMS/setBootConfigFromNVRAM.c b/modules/libcom/RTEMS/setBootConfigFromNVRAM.c index ecdbe5291..439980ae2 100644 --- a/modules/libcom/RTEMS/setBootConfigFromNVRAM.c +++ b/modules/libcom/RTEMS/setBootConfigFromNVRAM.c @@ -14,6 +14,11 @@ #include #ifdef RTEMS_LEGACY_STACK #include +#else +#include +#include +#include +#include #endif #include #include @@ -28,6 +33,8 @@ char *env_nfsServer; char *env_nfsPath; char *env_nfsMountPoint; +#if defined(HAVE_MOTLOAD) || defined(HAVE_PPCBUG) || defined(__mcf528x__) + extern char* rtems_bsdnet_bootp_cmdline; /* * Split argument string of form nfs_server:nfs_export: @@ -66,6 +73,7 @@ splitRtemsBsdnetBootpCmdline(void) } } +#if defined(HAVE_MOTLOAD) || defined(__mcf528x__) /* * Split NFS mount information of the form nfs_server:host_path:local_path */ @@ -91,6 +99,74 @@ splitNfsMountPath(char *nfsString) } } } +#endif /* HAVE_MOTLOAD || __mcf528x__ */ + +struct boot_net_config { + char *ip_address; /* static IP address of this device */ + char *netmask; /* subnet mask */ + char *gateway; /* default gateway */ + char *server; /* boot server; used as NTP/DNS fallback if not overridden */ + char *ntp_server; /* NTP server (falls back to server if NULL) */ + char *hostname; /* this device's hostname */ + char *dns_server; /* DNS resolver (falls back to server if NULL) */ + char *domainname; /* DNS domain name */ + char *bootp_boot_file; /* boot filename reported via BOOTP */ + uint32_t bootp_server_addr; /* server IPv4 address as stored in PPCBUG NVRAM */ +}; + +/* Configure network from boot_net_config. + * RTEMS_LEGACY_STACK: populate rtems_bsdnet_config fields. + * libbsd: configure the first hardware interface (index 1) with a static IP. + * Returns 0 on success, -1 on failure. */ +static int +applyNetConfig(const struct boot_net_config *cfg, + char *ntp_server_ip, size_t ntp_server_ip_size) +{ +#ifdef RTEMS_LEGACY_STACK + (void)ntp_server_ip; + (void)ntp_server_ip_size; + rtems_bsdnet_bootp_server_name = cfg->server; + rtems_bsdnet_config.name_server[0] = cfg->dns_server ? cfg->dns_server : cfg->server; + rtems_bsdnet_config.ntp_server[0] = cfg->ntp_server ? cfg->ntp_server : cfg->server; + rtems_bsdnet_config.gateway = cfg->gateway; + rtems_bsdnet_config.ifconfig->ip_netmask = cfg->netmask; + rtems_bsdnet_config.ifconfig->ip_address = cfg->ip_address; + rtems_bsdnet_config.hostname = cfg->hostname ? cfg->hostname : cfg->ip_address; + if (cfg->domainname) + rtems_bsdnet_config.domainname = cfg->domainname; + if (cfg->bootp_boot_file) + rtems_bsdnet_bootp_boot_file_name = cfg->bootp_boot_file; + if (cfg->bootp_server_addr) + rtems_bsdnet_bootp_server_address.s_addr = cfg->bootp_server_addr; +#else + char ifnamebuf[IF_NAMESIZE]; + char *ifname = if_indextoname(1, ifnamebuf); + if (ifname == NULL) { + printf("No network interface found\n"); + return -1; + } + printf("Configuring ifconfig with ip=%s, netmask=%s, gateway=%s\n", + cfg->ip_address ? cfg->ip_address : "NULL", + cfg->netmask ? cfg->netmask : "NULL", + cfg->gateway ? cfg->gateway : "NULL"); + if (cfg->ip_address && cfg->netmask) { + int exit_code = rtems_bsd_ifconfig(ifname, cfg->ip_address, + cfg->netmask, cfg->gateway); + if (exit_code != EX_OK) { + printf("rtems_bsd_ifconfig failed (exit code %d)\n", exit_code); + return -1; + } + } else { + printf("Skipping static IP address and netmask from NVRAM\n"); + return -1; + } + if (ntp_server_ip != NULL && ntp_server_ip_size > 0 && cfg->ntp_server != NULL) + snprintf(ntp_server_ip, ntp_server_ip_size, "%s", cfg->ntp_server); +#endif + return 0; +} + +#endif /* HAVE_MOTLOAD || HAVE_PPCBUG || __mcf528x__ */ #if defined(HAVE_MOTLOAD) @@ -158,12 +234,12 @@ motScriptParm(const char *mot_script_boot, char parm) return NULL; } -void -setBootConfigFromNVRAM(void) +int +setBootConfigFromNVRAM(char *ntp_server_ip, size_t ntp_server_ip_size) { - char *cp; const char *mot_script_boot; volatile char *nvp; + struct boot_net_config cfg = {0}; # if defined(BSP_NVRAM_BASE_ADDR) nvp = (volatile char *)(BSP_NVRAM_BASE_ADDR+0x70f8); @@ -172,12 +248,13 @@ setBootConfigFromNVRAM(void) 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; + return -1; } 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); + return -1; } close(fd); nvp = gev_buf; @@ -185,39 +262,57 @@ setBootConfigFromNVRAM(void) # 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; + /* + * Read network parameters from NVRAM + */ + if ((cfg.ip_address = gev("mot-/dev/enet0-cipa", nvp)) == NULL) { + cfg.ip_address = motScriptParm(mot_script_boot, 'c'); + } - 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 ((cfg.netmask = gev("mot-/dev/enet0-snma", nvp)) == NULL) { + cfg.netmask = motScriptParm(mot_script_boot, 'm'); + } + if ((cfg.gateway = gev("mot-/dev/enet0-gipa", nvp)) == NULL) { + cfg.gateway = motScriptParm(mot_script_boot, 'g'); + } + + if ((cfg.server = gev("mot-/dev/enet0-sipa", nvp)) == NULL) { + cfg.server = motScriptParm(mot_script_boot, 's'); + } + + + { + char *ntp_gev = gev("epics-ntpserver", nvp); + cfg.ntp_server = ntp_gev ? ntp_gev : cfg.server; + } + cfg.hostname = gev("rtems-client-name", nvp); + cfg.dns_server = gev("rtems-dns-server", nvp); + cfg.domainname = gev("rtems-dns-domainname", nvp); + cfg.bootp_boot_file = gev("mot-/dev/enet0-file", nvp); + if (cfg.bootp_boot_file == NULL) + cfg.bootp_boot_file = motScriptParm(mot_script_boot, 'f'); + + /* + * Apply network configuration + */ +#ifdef RTEMS_LEGACY_STACK + if (rtems_bsdnet_config.bootp != NULL) + return 0; +#endif + if (applyNetConfig(&cfg, ntp_server_ip, ntp_server_ip_size) != 0) + return -1; - 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); + { + char *tz = gev("epics-tz", nvp); + if (tz != NULL) + epicsEnvSet("TZ", tz); + } + return 0; } #elif defined(HAVE_PPCBUG) @@ -254,8 +349,8 @@ static char *addr(char *cbuf, uint32_t addr) return (char *)inet_ntop(AF_INET, &a, cbuf, INET_ADDRSTRLEN); } -void -setBootConfigFromNVRAM(void) +int +setBootConfigFromNVRAM(char *ntp_server_ip, size_t ntp_server_ip_size) { static struct ppcbug_nvram nvram; static char ip_address[INET_ADDRSTRLEN]; @@ -263,9 +358,6 @@ setBootConfigFromNVRAM(void) static char server[INET_ADDRSTRLEN]; static char gateway[INET_ADDRSTRLEN]; - if (rtems_bsdnet_config.bootp != NULL) - return; - /* * Get network configuration from PPCBUG. * The 'correct' way to do this would be to issue a .NETCFIG PPCBUG @@ -299,25 +391,30 @@ setBootConfigFromNVRAM(void) *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); + char * serverp = addr(server, nvram.ServerIPAddress); + struct boot_net_config cfg = { + addr(ip_address, nvram.ClientIPAddress), + addr(ip_netmask, nvram.SubnetIPAddressMask), + addr(gateway, nvram.GatewayIPAddress), + serverp, + serverp, /* ntp_server defaults to server */ + NULL, /* hostname */ + NULL, /* dns_server */ + NULL, /* domainname */ + nvram.BootFilenameString, /* bootp_boot_file */ + nvram.ServerIPAddress, /* bootp_server_addr */ + }; - rtems_bsdnet_bootp_boot_file_name = nvram.BootFilenameString; +#ifdef RTEMS_LEGACY_STACK + if (rtems_bsdnet_config.bootp != NULL) + return 0; +#endif + if (applyNetConfig(&cfg, ntp_server_ip, ntp_server_ip_size) != 0) + return -1; rtems_bsdnet_bootp_cmdline = nvram.ArgumentFilenameString; splitRtemsBsdnetBootpCmdline(); + return 0; } #elif defined(__mcf528x__) @@ -336,39 +433,49 @@ env(const char *parm, const char *defaultValue) return epicsStrDup(cp); } -void -setBootConfigFromNVRAM(void) +int +setBootConfigFromNVRAM(char *ntp_server_ip, size_t ntp_server_ip_size) { - const char *cp1; + char *server_str = env("SERVER", "192.168.0.1"); + struct boot_net_config cfg = { + env("IPADDR0", "192.168.0.2"), + env("NETMASK", "255.255.252.0"), + env("GATEWAY", NULL), + server_str, + env("NTPSERVER", server_str), + env("HOSTNAME", "iocNobody"), + env("NAMESERVER", server_str), + env("DOMAIN", NULL), + env("BOOTFILE", "uC5282App.boot"), + 0, /* bootp_server_addr */ + }; +#ifdef RTEMS_LEGACY_STACK 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"); + return 0; +#endif + if (applyNetConfig(&cfg, ntp_server_ip, ntp_server_ip_size) != 0) + return -1; rtems_bsdnet_bootp_cmdline = env("CMDLINE", "epics/iocBoot/iocNobody/st.cmd"); + splitRtemsBsdnetBootpCmdline(); splitNfsMountPath(env("NFSMOUNT", NULL)); - if ((cp1 = env("TZ", NULL)) != NULL) - epicsEnvSet("TZ", cp1); + { + char *tz = env("TZ", NULL); + if (tz != NULL) + epicsEnvSet("TZ", tz); + } + return 0; } #else /* * Placeholder for systems without NVRAM */ -void -setBootConfigFromNVRAM(void) +int +setBootConfigFromNVRAM(char *ntp_server_ip, size_t ntp_server_ip_size) { printf("SYSTEM HAS NO NON-VOLATILE RAM!\n"); printf("YOU MUST USE SOME OTHER METHOD TO OBTAIN NETWORK CONFIGURATION\n"); + return -1; } #endif