2002-11-03 00:01:44 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2002-11-03 00:01:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <asm/processor.h>
|
2010-09-09 17:18:00 +00:00
|
|
|
#include <asm/ppc4xx-i2c.h>
|
2002-11-03 00:01:44 +00:00
|
|
|
#include <command.h>
|
|
|
|
#include <rtc.h>
|
2003-05-20 14:25:27 +00:00
|
|
|
#include <post.h>
|
2002-11-03 00:01:44 +00:00
|
|
|
#include <net.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
|
|
|
|
#define L1_MEMSIZE (32*1024*1024)
|
|
|
|
|
|
|
|
/* the std. DHCP stufff */
|
|
|
|
#define DHCP_ROUTER 3
|
|
|
|
#define DHCP_NETMASK 1
|
|
|
|
#define DHCP_BOOTFILE 67
|
|
|
|
#define DHCP_ROOTPATH 17
|
|
|
|
#define DHCP_HOSTNAME 12
|
|
|
|
|
|
|
|
/* some extras used by CRAY
|
|
|
|
*
|
|
|
|
* on the server this looks like:
|
|
|
|
*
|
|
|
|
* option L1-initrd-image code 224 = string;
|
|
|
|
* option L1-initrd-image "/opt/craysv2/craymcu/l1/flash/initrd.image"
|
|
|
|
*/
|
|
|
|
#define DHCP_L1_INITRD 224
|
|
|
|
|
|
|
|
/* new, [better?] way via official vendor-extensions, defining an option
|
|
|
|
* space.
|
|
|
|
* on the server this looks like:
|
|
|
|
*
|
2003-05-20 14:25:27 +00:00
|
|
|
* option space CRAYL1;
|
|
|
|
* option CRAYL1.initrd code 3 = string;
|
|
|
|
* ..etc...
|
2002-11-03 00:01:44 +00:00
|
|
|
*/
|
|
|
|
#define DHCP_VENDOR_SPECX 43
|
|
|
|
#define DHCP_VX_INITRD 3
|
|
|
|
#define DHCP_VX_BOOTCMD 4
|
2003-05-20 14:25:27 +00:00
|
|
|
#define DHCP_VX_BOOTARGS 5
|
2002-11-03 00:01:44 +00:00
|
|
|
#define DHCP_VX_ROOTDEV 6
|
2003-05-20 14:25:27 +00:00
|
|
|
#define DHCP_VX_FROMFLASH 7
|
|
|
|
#define DHCP_VX_BOOTSCRIPT 8
|
|
|
|
#define DHCP_VX_RCFILE 9
|
|
|
|
#define DHCP_VX_MAGIC 10
|
2002-11-03 00:01:44 +00:00
|
|
|
|
|
|
|
/* Things DHCP server can tellme about. If there's no flash address, then
|
|
|
|
* they dont participate in 'update' to flash, and we force their values
|
|
|
|
* back to '0' every boot to be sure to get them fresh from DHCP. Yes, I
|
|
|
|
* know this is a pain...
|
|
|
|
*
|
|
|
|
* If I get no bootfile, boot from flash. If rootpath, use that. If no
|
|
|
|
* rootpath use initrd in flash.
|
|
|
|
*/
|
|
|
|
typedef struct dhcp_item_s {
|
|
|
|
u8 dhcp_option;
|
|
|
|
u8 dhcp_vendor_option;
|
|
|
|
char *dhcpvalue;
|
|
|
|
char *envname;
|
|
|
|
} dhcp_item_t;
|
|
|
|
static dhcp_item_t Things[] = {
|
|
|
|
{DHCP_ROUTER, 0, NULL, "gateway"},
|
|
|
|
{DHCP_NETMASK, 0, NULL, "netmask"},
|
|
|
|
{DHCP_BOOTFILE, 0, NULL, "bootfile"},
|
|
|
|
{DHCP_ROOTPATH, 0, NULL, "rootpath"},
|
|
|
|
{DHCP_HOSTNAME, 0, NULL, "hostname"},
|
|
|
|
{DHCP_L1_INITRD, 0, NULL, "initrd"},
|
|
|
|
/* and the other way.. */
|
|
|
|
{DHCP_VENDOR_SPECX, DHCP_VX_INITRD, NULL, "initrd"},
|
|
|
|
{DHCP_VENDOR_SPECX, DHCP_VX_BOOTCMD, NULL, "bootcmd"},
|
2003-05-20 14:25:27 +00:00
|
|
|
{DHCP_VENDOR_SPECX, DHCP_VX_FROMFLASH, NULL, "fromflash"},
|
|
|
|
{DHCP_VENDOR_SPECX, DHCP_VX_BOOTSCRIPT, NULL, "bootscript"},
|
|
|
|
{DHCP_VENDOR_SPECX, DHCP_VX_RCFILE, NULL, "rcfile"},
|
|
|
|
{DHCP_VENDOR_SPECX, DHCP_VX_BOOTARGS, NULL, "xbootargs"},
|
2002-11-03 00:01:44 +00:00
|
|
|
{DHCP_VENDOR_SPECX, DHCP_VX_ROOTDEV, NULL, NULL},
|
2003-05-20 14:25:27 +00:00
|
|
|
{DHCP_VENDOR_SPECX, DHCP_VX_MAGIC, NULL, NULL}
|
2002-11-03 00:01:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define N_THINGS ((sizeof(Things))/(sizeof(dhcp_item_t)))
|
|
|
|
|
2003-05-20 14:25:27 +00:00
|
|
|
extern char bootscript[];
|
|
|
|
|
|
|
|
/* Here is the boot logic as HUSH script. Overridden by any TFP provided
|
|
|
|
* bootscript file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void init_sdram (void);
|
2002-11-03 00:01:44 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2004-01-20 23:12:12 +00:00
|
|
|
int board_early_init_f (void)
|
2002-11-03 00:01:44 +00:00
|
|
|
{
|
2003-05-20 14:25:27 +00:00
|
|
|
/* Running from ROM: global data is still READONLY */
|
|
|
|
init_sdram ();
|
2009-09-24 07:55:50 +00:00
|
|
|
mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
|
|
|
|
mtdcr (UIC0ER, 0x00000000); /* disable all ints */
|
|
|
|
mtdcr (UIC0CR, 0x00000020); /* set all but FPGA SMI to be non-critical */
|
|
|
|
mtdcr (UIC0PR, 0xFFFFFFE0); /* set int polarities */
|
|
|
|
mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */
|
|
|
|
mtdcr (UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority */
|
|
|
|
mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */
|
2002-11-03 00:01:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
int checkboard (void)
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
2003-05-20 14:25:27 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
2002-11-03 00:01:44 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
int misc_init_r (void)
|
|
|
|
{
|
2005-10-13 14:45:02 +00:00
|
|
|
char *s, *e;
|
2002-11-03 00:01:44 +00:00
|
|
|
image_header_t *hdr;
|
|
|
|
time_t timestamp;
|
|
|
|
struct rtc_time tm;
|
2003-05-20 14:25:27 +00:00
|
|
|
char bootcmd[32];
|
2002-11-03 00:01:44 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
hdr = (image_header_t *) (CONFIG_SYS_MONITOR_BASE - image_get_header_size ());
|
2008-02-04 07:28:09 +00:00
|
|
|
#if defined(CONFIG_FIT)
|
2008-02-29 13:58:34 +00:00
|
|
|
if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
|
2008-02-04 07:28:09 +00:00
|
|
|
puts ("Non legacy image format not supported\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-01-08 17:14:09 +00:00
|
|
|
timestamp = (time_t)image_get_time (hdr);
|
2002-11-03 00:01:44 +00:00
|
|
|
to_tm (timestamp, &tm);
|
|
|
|
printf ("Welcome to U-Boot on Cray L1. Compiled %4d-%02d-%02d %2d:%02d:%02d (UTC)\n", tm.tm_year, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
|
|
|
|
|
|
|
|
#define FACTORY_SETTINGS 0xFFFC0000
|
|
|
|
if ((s = getenv ("ethaddr")) == NULL) {
|
2005-10-13 14:45:02 +00:00
|
|
|
e = (char *) (FACTORY_SETTINGS);
|
2002-11-03 00:01:44 +00:00
|
|
|
if (*(e + 0) != '0'
|
|
|
|
|| *(e + 1) != '0'
|
|
|
|
|| *(e + 2) != ':'
|
|
|
|
|| *(e + 3) != '4' || *(e + 4) != '0' || *(e + 17) != '\0') {
|
|
|
|
printf ("No valid MAC address in flash location 0x3C0000!\n");
|
|
|
|
} else {
|
|
|
|
printf ("Factory MAC: %s\n", e);
|
|
|
|
setenv ("ethaddr", e);
|
|
|
|
}
|
|
|
|
}
|
2009-04-01 21:34:12 +00:00
|
|
|
sprintf (bootcmd,"source %X",(unsigned)bootscript);
|
2003-05-20 14:25:27 +00:00
|
|
|
setenv ("bootcmd", bootcmd);
|
2002-11-03 00:01:44 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* stubs so we can print dates w/o any nvram RTC.*/
|
2008-03-20 14:56:04 +00:00
|
|
|
int rtc_get (struct rtc_time *tmp)
|
2002-11-03 00:01:44 +00:00
|
|
|
{
|
2008-03-20 14:56:04 +00:00
|
|
|
return 0;
|
2002-11-03 00:01:44 +00:00
|
|
|
}
|
2008-09-01 21:06:23 +00:00
|
|
|
int rtc_set (struct rtc_time *tmp)
|
2002-11-03 00:01:44 +00:00
|
|
|
{
|
2008-09-01 21:06:23 +00:00
|
|
|
return 0;
|
2002-11-03 00:01:44 +00:00
|
|
|
}
|
|
|
|
void rtc_reset (void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2003-05-20 14:25:27 +00:00
|
|
|
/* Do sdram bank init in C so I can read it..no console to print to yet!
|
2002-11-03 00:01:44 +00:00
|
|
|
*/
|
2003-05-20 14:25:27 +00:00
|
|
|
static void init_sdram (void)
|
2002-11-03 00:01:44 +00:00
|
|
|
{
|
2003-05-20 14:25:27 +00:00
|
|
|
unsigned long tmp;
|
2002-11-03 00:01:44 +00:00
|
|
|
|
|
|
|
/* write SDRAM bank 0 register */
|
2009-09-24 11:59:57 +00:00
|
|
|
mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR);
|
2009-09-09 14:25:29 +00:00
|
|
|
mtdcr (SDRAM0_CFGDATA, 0x00062001);
|
2002-11-03 00:01:44 +00:00
|
|
|
|
|
|
|
/* Set the SDRAM Timing reg, SDTR1 and the refresh timer reg, RTR. */
|
|
|
|
/* To set the appropriate timings, we need to know the SDRAM speed. */
|
|
|
|
/* We can use the PLB speed since the SDRAM speed is the same as */
|
|
|
|
/* the PLB speed. The PLB speed is the FBK divider times the */
|
2008-10-19 00:35:50 +00:00
|
|
|
/* 405GP reference clock, which on the L1 is 25MHz. */
|
|
|
|
/* Thus, if FBK div is 2, SDRAM is 50MHz; if FBK div is 3, SDRAM is */
|
|
|
|
/* 150MHz; if FBK is 3, SDRAM is 150MHz. */
|
2002-11-03 00:01:44 +00:00
|
|
|
|
|
|
|
/* divisor = ((mfdcr(strap)>> 28) & 0x3); */
|
|
|
|
|
2008-10-19 00:35:50 +00:00
|
|
|
/* write SDRAM timing for 100MHz. */
|
2009-09-24 11:59:57 +00:00
|
|
|
mtdcr (SDRAM0_CFGADDR, SDRAM0_TR);
|
2009-09-09 14:25:29 +00:00
|
|
|
mtdcr (SDRAM0_CFGDATA, 0x0086400D);
|
2002-11-03 00:01:44 +00:00
|
|
|
|
|
|
|
/* write SDRAM refresh interval register */
|
2009-09-24 11:59:57 +00:00
|
|
|
mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR);
|
2009-09-09 14:25:29 +00:00
|
|
|
mtdcr (SDRAM0_CFGDATA, 0x05F00000);
|
2002-11-03 00:01:44 +00:00
|
|
|
udelay (200);
|
|
|
|
|
|
|
|
/* sdram controller.*/
|
2009-09-24 11:59:57 +00:00
|
|
|
mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
|
2009-09-09 14:25:29 +00:00
|
|
|
mtdcr (SDRAM0_CFGDATA, 0x90800000);
|
2002-11-03 00:01:44 +00:00
|
|
|
udelay (200);
|
|
|
|
|
2003-05-20 14:25:27 +00:00
|
|
|
/* initially, disable ECC on all banks */
|
|
|
|
udelay (200);
|
2009-09-24 11:59:57 +00:00
|
|
|
mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
|
2009-09-09 14:25:29 +00:00
|
|
|
tmp = mfdcr (SDRAM0_CFGDATA);
|
2002-11-03 00:01:44 +00:00
|
|
|
tmp &= 0xff0fffff;
|
2009-09-24 11:59:57 +00:00
|
|
|
mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
|
2009-09-09 14:25:29 +00:00
|
|
|
mtdcr (SDRAM0_CFGDATA, tmp);
|
2002-11-03 00:01:44 +00:00
|
|
|
|
2003-05-20 14:25:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int memory_post_test (int flags);
|
|
|
|
|
|
|
|
int testdram (void)
|
|
|
|
{
|
|
|
|
unsigned long tmp;
|
|
|
|
uint *pstart = (uint *) 0x00000000;
|
|
|
|
uint *pend = (uint *) L1_MEMSIZE;
|
|
|
|
uint *p;
|
|
|
|
|
Rename getenv_r() into getenv_f()
While running from flash, i. e. before relocation, we have only a
limited C runtime environment without writable data segment. In this
phase, some configurations (for example with environment in EEPROM)
must not use the normal getenv(), but a special function. This
function had been called getenv_r(), with the idea that the "_r"
suffix would mean the same as in the _r_eentrant versions of some of
the C library functions (for example getdate vs. getdate_r, getgrent
vs. getgrent_r, etc.).
Unfortunately this was a misleading name, as in U-Boot the "_r"
generally means "running from RAM", i. e. _after_ relocation.
To avoid confusion, rename into getenv_f() [as "running from flash"]
Signed-off-by: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>
2010-07-24 19:55:43 +00:00
|
|
|
if (getenv_f("booted",NULL,0) <= 0)
|
2003-05-20 14:25:27 +00:00
|
|
|
{
|
|
|
|
printf ("testdram..");
|
|
|
|
/*AA*/
|
|
|
|
for (p = pstart; p < pend; p++)
|
|
|
|
*p = 0xaaaaaaaa;
|
|
|
|
for (p = pstart; p < pend; p++) {
|
|
|
|
if (*p != 0xaaaaaaaa) {
|
2003-06-27 21:31:46 +00:00
|
|
|
printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
|
2003-05-20 14:25:27 +00:00
|
|
|
(uint) p, *p, 0xaaaaaaaa);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*55*/
|
|
|
|
for (p = pstart; p < pend; p++)
|
|
|
|
*p = 0x55555555;
|
|
|
|
for (p = pstart; p < pend; p++) {
|
|
|
|
if (*p != 0x55555555) {
|
2003-06-27 21:31:46 +00:00
|
|
|
printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
|
2003-05-20 14:25:27 +00:00
|
|
|
(uint) p, *p, 0x55555555);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*addr*/
|
|
|
|
for (p = pstart; p < pend; p++)
|
|
|
|
*p = (unsigned)p;
|
|
|
|
for (p = pstart; p < pend; p++) {
|
|
|
|
if (*p != (unsigned)p) {
|
2003-06-27 21:31:46 +00:00
|
|
|
printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
|
2003-05-20 14:25:27 +00:00
|
|
|
(uint) p, *p, (uint)p);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf ("Success. ");
|
|
|
|
}
|
|
|
|
printf ("Enable ECC..");
|
|
|
|
|
2009-09-24 11:59:57 +00:00
|
|
|
mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
|
2009-09-09 14:25:29 +00:00
|
|
|
tmp = (mfdcr (SDRAM0_CFGDATA) & ~0xFFE00000) | 0x90800000;
|
2009-09-24 11:59:57 +00:00
|
|
|
mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
|
2009-09-09 14:25:29 +00:00
|
|
|
mtdcr (SDRAM0_CFGDATA, tmp);
|
2002-11-03 00:01:44 +00:00
|
|
|
udelay (600);
|
2003-05-20 14:25:27 +00:00
|
|
|
for (p = (unsigned long) 0; ((unsigned long) p < L1_MEMSIZE); *p++ = 0L)
|
|
|
|
;
|
2002-11-03 00:01:44 +00:00
|
|
|
udelay (400);
|
2009-09-24 11:59:57 +00:00
|
|
|
mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
|
2009-09-09 14:25:29 +00:00
|
|
|
tmp = mfdcr (SDRAM0_CFGDATA);
|
2002-11-03 00:01:44 +00:00
|
|
|
tmp |= 0x00800000;
|
2009-09-09 14:25:29 +00:00
|
|
|
mtdcr (SDRAM0_CFGDATA, tmp);
|
2002-11-03 00:01:44 +00:00
|
|
|
udelay (400);
|
2003-05-20 14:25:27 +00:00
|
|
|
printf ("enabled.\n");
|
|
|
|
return (0);
|
2002-11-03 00:01:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
static u8 *dhcp_env_update (u8 thing, u8 * pop)
|
|
|
|
{
|
|
|
|
u8 i, oplen;
|
|
|
|
|
|
|
|
oplen = *(pop + 1);
|
|
|
|
|
|
|
|
if ((Things[thing].dhcpvalue = malloc (oplen)) == NULL) {
|
|
|
|
printf ("Whoops! failed to malloc space for DHCP thing %s\n",
|
|
|
|
Things[thing].envname);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (i = 0; (i < oplen); i++)
|
|
|
|
if ((*(Things[thing].dhcpvalue + i) = *(pop + 2 + i)) == ' ')
|
|
|
|
break;
|
|
|
|
*(Things[thing].dhcpvalue + i) = '\0';
|
|
|
|
|
|
|
|
/* set env. */
|
|
|
|
if (Things[thing].envname)
|
2003-05-20 14:25:27 +00:00
|
|
|
{
|
2002-11-03 00:01:44 +00:00
|
|
|
setenv (Things[thing].envname, Things[thing].dhcpvalue);
|
2003-05-20 14:25:27 +00:00
|
|
|
}
|
2005-10-13 14:45:02 +00:00
|
|
|
return ((u8 *)(Things[thing].dhcpvalue));
|
2002-11-03 00:01:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
u8 *dhcp_vendorex_prep (u8 * e)
|
|
|
|
{
|
|
|
|
u8 thing;
|
|
|
|
|
|
|
|
/* ask for the things I want. */
|
|
|
|
*e++ = 55; /* Parameter Request List */
|
|
|
|
*e++ = N_THINGS;
|
|
|
|
for (thing = 0; thing < N_THINGS; thing++)
|
|
|
|
*e++ = Things[thing].dhcp_option;
|
|
|
|
*e++ = 255;
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* .. return NULL means it wasnt mine, non-null means I got it..*/
|
|
|
|
u8 *dhcp_vendorex_proc (u8 * pop)
|
|
|
|
{
|
|
|
|
u8 oplen, *sub_op, sub_oplen, *retval;
|
|
|
|
u8 thing = 0;
|
|
|
|
|
|
|
|
retval = NULL;
|
|
|
|
oplen = *(pop + 1);
|
|
|
|
/* if pop is vender spec indicator, there are sub-options. */
|
|
|
|
if (*pop == DHCP_VENDOR_SPECX) {
|
|
|
|
for (sub_op = pop + 2;
|
|
|
|
oplen && (sub_oplen = *(sub_op + 1));
|
|
|
|
oplen -= sub_oplen, sub_op += (sub_oplen + 2)) {
|
|
|
|
for (thing = 0; thing < N_THINGS; thing++) {
|
|
|
|
if (*sub_op == Things[thing].dhcp_vendor_option) {
|
2003-05-20 14:25:27 +00:00
|
|
|
if (!(retval = dhcp_env_update (thing, sub_op))) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-11-03 00:01:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (thing = 0; thing < N_THINGS; thing++) {
|
|
|
|
if (*pop == Things[thing].dhcp_option)
|
|
|
|
if (!(retval = dhcp_env_update (thing, pop)))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2003-05-20 14:25:27 +00:00
|
|
|
return (pop);
|
2002-11-03 00:01:44 +00:00
|
|
|
}
|