Allow configuration from PPCBUG NVRAM.

This commit is contained in:
W. Eric Norum
2004-09-17 20:48:09 +00:00
parent 88702dd180
commit f41a7910c4
5 changed files with 155 additions and 34 deletions

View File

@@ -15,6 +15,7 @@ SRCS += rtems_config.c
SRCS += rtems_netconfig.c
SRCS += rtems_util.c
SRCS += rtems_dummyreg.c
SRCS += setBootConfigFromPPCBUGNVRAM.c
LIBRARY_RTEMS = rtemsCom
LIBRARY_SRCS = $(SRCS) $(BUILD_ARCHS)

View File

@@ -47,5 +47,6 @@ rtems_task Init (rtems_task_argument argument);
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_RTC_DRIVER
#include <confdefs.h>

View File

@@ -265,6 +265,8 @@ Init (rtems_task_argument ignored)
char *argv[3] = { arg0, arg1, NULL };
rtems_interval ticksPerSecond;
rtems_task_priority newpri;
rtems_status_code sc;
rtems_time_of_day now;
/*
* Get configuration
@@ -277,6 +279,12 @@ Init (rtems_task_argument ignored)
#if defined(__i386__)
initRemoteGdb(ticksPerSecond);
#endif
#if defined(__PPC) && defined(HAVE_PPCBUG)
{
extern void setBootConfigFromPPCBUGNVRAM(void);
setBootConfigFromPPCBUGNVRAM();
}
#endif
/*
* Override RTEMS configuration
@@ -307,28 +315,32 @@ Init (rtems_task_argument ignored)
rtems_bsdnet_initialize_network ();
printf ("***** Initializing TFTP *****\n");
rtems_bsdnet_initialize_tftp_filesystem ();
for (i = 0 ; ; i++) {
printf ("***** Initializing NTP *****\n");
if (rtems_bsdnet_synchronize_ntp (0, 0) >= 0)
break;
rtems_task_wake_after (5*ticksPerSecond);
if (i >= 12) {
rtems_status_code sc;
rtems_time_of_day now;
printf (" *************** WARNING ***************\n");
printf (" ***** NO RESPONSE FROM NTP SERVER *****\n");
printf (" ***** TIME SET TO DEFAULT VALUE *****\n");
printf (" ***************************************\n");
now.year = 2001;
now.month = 1;
now.day = 1;
now.hour = 0;
now.minute = 0;
now.second = 0;
now.ticks = 0;
if ((sc = rtems_clock_set (&now)) != RTEMS_SUCCESSFUL)
printf ("***** Can't set time: %s\n", rtems_status_text (sc));
break;
/*
* Use BSP-supplied time of day if available
*/
if (rtems_clock_get(RTEMS_CLOCK_GET_TOD,&now) != RTEMS_SUCCESSFUL) {
for (i = 0 ; ; i++) {
printf ("***** Initializing NTP *****\n");
if (rtems_bsdnet_synchronize_ntp (0, 0) >= 0)
break;
rtems_task_wake_after (5*ticksPerSecond);
if (i >= 12) {
printf (" *************** WARNING ***************\n");
printf (" ***** NO RESPONSE FROM NTP SERVER *****\n");
printf (" ***** TIME SET TO DEFAULT VALUE *****\n");
printf (" ***************************************\n");
now.year = 2001;
now.month = 1;
now.day = 1;
now.hour = 0;
now.minute = 0;
now.second = 0;
now.ticks = 0;
if ((sc = rtems_clock_set (&now)) != RTEMS_SUCCESSFUL)
printf ("***** Can't set time: %s\n", rtems_status_text (sc));
break;
}
}
}

View File

@@ -38,7 +38,6 @@ static struct rtems_bsdnet_ifconfig loopback_config = {
* application directory and make the appropriate changes.
*/
#if defined(__i386__)
extern int rtems_fxp_attach (struct rtems_bsdnet_ifconfig *, int);
static struct rtems_bsdnet_ifconfig fxp_driver_config = {
"fxp1", /* name */
@@ -53,16 +52,22 @@ static struct rtems_bsdnet_ifconfig e3c509_driver_config = {
};
#define FIRST_DRIVER_CONFIG &e3c509_driver_config
#else
/*
* FIXME: This really belongs in the mcp750 BSP
*/
#if defined(__PPC) && defined(mpc750) && !defined(RTEMS_BSP_NETWORK_DRIVER_NAME) && !defined(RTEMS_BSP_NETWORK_DRIVER_ATTACH)
# define RTEMS_BSP_NETWORK_DRIVER_NAME "dc1"
# define RTEMS_BSP_NETWORK_DRIVER_ATTACH rtems_dec21140_driver_attach
extern int rtems_dec21140_driver_attach();
#endif
#elif defined(__PPC)
/*
* FIXME: This really belongs in the BSP
*/
# if defined(mpc750)
# 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
# if defined(HAVE_PPCBUG)
# define MY_DO_BOOTP NULL
# endif
static struct rtems_bsdnet_ifconfig bsp_driver_config = {
RTEMS_BSP_NETWORK_DRIVER_NAME, /* name */
@@ -73,9 +78,30 @@ static struct rtems_bsdnet_ifconfig 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
/*
* Network configuration
*/
struct rtems_bsdnet_config rtems_bsdnet_config = {
FIRST_DRIVER_CONFIG, /* Link to next interface */
rtems_bsdnet_do_bootp, /* Use BOOTP to get network configuration */
MY_DO_BOOTP, /* How to find network config */
0, /* If 0 then the network daemons will run at a */
/* priority just less than the lowest-priority */
/* EPICS scan thread. */
@@ -83,4 +109,6 @@ struct rtems_bsdnet_config rtems_bsdnet_config = {
/* at this *RTEMS* priority */
180*1024, /* MBUF space */
350*1024, /* MBUF cluster space */
NULL, /* Host name */
MY_DOMAINNAME, /* Domain name */
};

View File

@@ -0,0 +1,79 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <rtems/rtems_bsdnet.h>
#if defined(__PPC)
struct ppcbug_nvram {
rtems_unsigned32 PacketVersionIdentifier;
rtems_unsigned32 NodeControlMemoryAddress;
rtems_unsigned32 BootFileLoadAddress;
rtems_unsigned32 BootFileExecutionAddress;
rtems_unsigned32 BootFileExecutionDelay;
rtems_unsigned32 BootFileLength;
rtems_unsigned32 BootFileByteOffset;
rtems_unsigned32 TraceBufferAddress;
rtems_unsigned32 ClientIPAddress;
rtems_unsigned32 ServerIPAddress;
rtems_unsigned32 SubnetIPAddressMask;
rtems_unsigned32 BroadcastIPAddressMask;
rtems_unsigned32 GatewayIPAddress;
rtems_unsigned8 BootpRarpRetry;
rtems_unsigned8 TftpRarpRetry;
rtems_unsigned8 BootpRarpControl;
rtems_unsigned8 UpdateControl;
char BootFilenameString[64];
char ArgumentFilenameString[64];
};
#define PPCBUG_NVRAM ((void *)0xFFE81000)
static char *addr(char *cbuf, rtems_unsigned32 addr)
{
struct in_addr a;
if ((a.s_addr = addr) == 0)
return NULL;
return (char *)inet_ntop(AF_INET, &a, cbuf, INET_ADDRSTRLEN);
}
void
setBootConfigFromPPCBUGNVRAM(void)
{
char *d;
volatile char *s;
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];
/*
* NVRAM must be accessed a byte at a time
*/
s = (volatile char *)PPCBUG_NVRAM;
d = (char *)&nvram;
while (d < ((char *)&nvram + sizeof(nvram)))
*d++ = *s++;
/*
* Assume that the boot server is also the name server and log server!
*/
rtems_bsdnet_config.name_server[0] =
rtems_bsdnet_bootp_server_name =
rtems_bsdnet_config.log_host = 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;
}
#endif /* defined(__PPC) */