L1.c 10.1 KB
Newer Older
W
wdenk 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/*
 * (C) Copyright 2000
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#include <common.h>
#include <asm/processor.h>
26
#include <4xx_i2c.h>
W
wdenk 已提交
27 28
#include <command.h>
#include <rtc.h>
W
wdenk 已提交
29
#include <post.h>
W
wdenk 已提交
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
#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:
 *
W
wdenk 已提交
55 56 57
 * option space CRAYL1;
 * option CRAYL1.initrd     code 3 = string;
 * ..etc...
W
wdenk 已提交
58 59 60 61
 */
#define DHCP_VENDOR_SPECX   43
#define DHCP_VX_INITRD       3
#define DHCP_VX_BOOTCMD      4
W
wdenk 已提交
62
#define DHCP_VX_BOOTARGS     5
W
wdenk 已提交
63
#define DHCP_VX_ROOTDEV      6
W
wdenk 已提交
64 65 66 67
#define DHCP_VX_FROMFLASH    7
#define DHCP_VX_BOOTSCRIPT   8
#define DHCP_VX_RCFILE	     9
#define DHCP_VX_MAGIC        10
W
wdenk 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

/* 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"},
W
wdenk 已提交
93 94 95 96
	{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"},
W
wdenk 已提交
97
	{DHCP_VENDOR_SPECX, DHCP_VX_ROOTDEV, NULL, NULL},
W
wdenk 已提交
98
	{DHCP_VENDOR_SPECX, DHCP_VX_MAGIC, NULL, NULL}
W
wdenk 已提交
99 100 101 102
};

#define N_THINGS ((sizeof(Things))/(sizeof(dhcp_item_t)))

W
wdenk 已提交
103 104 105 106 107 108 109
extern char bootscript[];

/* Here is the boot logic as HUSH script. Overridden by any TFP provided
 * bootscript file.
 */

static void init_sdram (void);
W
wdenk 已提交
110 111

/* ------------------------------------------------------------------------- */
112
int board_early_init_f (void)
W
wdenk 已提交
113
{
W
wdenk 已提交
114 115
	/* Running from ROM: global data is still READONLY */
	init_sdram ();
W
wdenk 已提交
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
	mtdcr (uicsr, 0xFFFFFFFF);	/* clear all ints */
	mtdcr (uicer, 0x00000000);	/* disable all ints */
	mtdcr (uiccr, 0x00000020);	/* set all but FPGA SMI to be non-critical */
	mtdcr (uicpr, 0xFFFFFFE0);	/* set int polarities */
	mtdcr (uictr, 0x10000000);	/* set int trigger levels */
	mtdcr (uicvcr, 0x00000001);	/* set vect base=0,INT0 highest priority */
	mtdcr (uicsr, 0xFFFFFFFF);	/* clear all ints */
	return 0;
}

/* ------------------------------------------------------------------------- */
int checkboard (void)
{
	return (0);
}
W
wdenk 已提交
131
/* ------------------------------------------------------------------------- */
W
wdenk 已提交
132 133 134 135

/* ------------------------------------------------------------------------- */
int misc_init_r (void)
{
W
Wolfgang Denk 已提交
136
	char *s, *e;
W
wdenk 已提交
137 138 139
	image_header_t *hdr;
	time_t timestamp;
	struct rtc_time tm;
W
wdenk 已提交
140
	char bootcmd[32];
W
wdenk 已提交
141

142
	hdr = (image_header_t *) (CFG_MONITOR_BASE - image_get_header_size ());
143
#if defined(CONFIG_FIT)
144
	if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
145 146 147 148 149
		puts ("Non legacy image format not supported\n");
		return -1;
	}
#endif

150
	timestamp = (time_t)image_get_time (hdr);
W
wdenk 已提交
151 152 153 154 155
	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) {
W
Wolfgang Denk 已提交
156
		e = (char *) (FACTORY_SETTINGS);
W
wdenk 已提交
157 158 159 160 161 162 163 164 165 166
		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);
		}
	}
W
wdenk 已提交
167 168
	sprintf (bootcmd,"autoscript %X",(unsigned)bootscript);
	setenv ("bootcmd", bootcmd);
W
wdenk 已提交
169 170 171 172
	return (0);
}

/* ------------------------------------------------------------------------- */
173
phys_size_t initdram (int board_type)
W
wdenk 已提交
174 175 176 177 178 179
{
	return (L1_MEMSIZE);
}

/* ------------------------------------------------------------------------- */
/* stubs so we can print dates w/o any nvram RTC.*/
Y
Yuri Tikhonov 已提交
180
int rtc_get (struct rtc_time *tmp)
W
wdenk 已提交
181
{
Y
Yuri Tikhonov 已提交
182
	return 0;
W
wdenk 已提交
183
}
184
int rtc_set (struct rtc_time *tmp)
W
wdenk 已提交
185
{
186
	return 0;
W
wdenk 已提交
187 188 189 190 191 192 193
}
void rtc_reset (void)
{
	return;
}

/* ------------------------------------------------------------------------- */
W
wdenk 已提交
194
/*  Do sdram bank init in C so I can read it..no console to print to yet!
W
wdenk 已提交
195
 */
W
wdenk 已提交
196
static void init_sdram (void)
W
wdenk 已提交
197
{
W
wdenk 已提交
198
 unsigned long tmp;
W
wdenk 已提交
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227

	/* write SDRAM bank 0 register */
	mtdcr (memcfga, mem_mb0cf);
	mtdcr (memcfgd, 0x00062001);

/* 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		*/
/* 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.				*/

	/* divisor = ((mfdcr(strap)>> 28) & 0x3); */

/* write SDRAM timing for 100Mhz. */
	mtdcr (memcfga, mem_sdtr1);
	mtdcr (memcfgd, 0x0086400D);

/* write SDRAM refresh interval register */
	mtdcr (memcfga, mem_rtr);
	mtdcr (memcfgd, 0x05F00000);
	udelay (200);

/* sdram controller.*/
	mtdcr (memcfga, mem_mcopt1);
	mtdcr (memcfgd, 0x90800000);
	udelay (200);

W
wdenk 已提交
228 229
/* initially, disable ECC on all banks */
	udelay (200);
W
wdenk 已提交
230 231 232 233 234 235
	mtdcr (memcfga, mem_ecccf);
	tmp = mfdcr (memcfgd);
	tmp &= 0xff0fffff;
	mtdcr (memcfga, mem_ecccf);
	mtdcr (memcfgd, tmp);

W
wdenk 已提交
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
	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;

	if (getenv_r("booted",NULL,0) <= 0)
	{
		printf ("testdram..");
	/*AA*/
		for (p = pstart; p < pend; p++)
			*p = 0xaaaaaaaa;
		for (p = pstart; p < pend; p++) {
			if (*p != 0xaaaaaaaa) {
W
wdenk 已提交
256
				printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
W
wdenk 已提交
257 258 259 260 261 262 263 264 265
						(uint) p, *p, 0xaaaaaaaa);
				return 1;
			}
		}
	/*55*/
		for (p = pstart; p < pend; p++)
			*p = 0x55555555;
		for (p = pstart; p < pend; p++) {
			if (*p != 0x55555555) {
W
wdenk 已提交
266
				printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
W
wdenk 已提交
267 268 269 270 271 272 273 274 275
						(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) {
W
wdenk 已提交
276
				printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
W
wdenk 已提交
277 278 279 280 281 282 283 284
						(uint) p, *p, (uint)p);
				return 1;
			}
		}
		printf ("Success. ");
	}
	printf ("Enable ECC..");

W
wdenk 已提交
285 286 287 288 289
	mtdcr (memcfga, mem_mcopt1);
	tmp = (mfdcr (memcfgd) & ~0xFFE00000) | 0x90800000;
	mtdcr (memcfga, mem_mcopt1);
	mtdcr (memcfgd, tmp);
	udelay (600);
W
wdenk 已提交
290 291
	for (p = (unsigned long) 0; ((unsigned long) p < L1_MEMSIZE); *p++ = 0L)
		;
W
wdenk 已提交
292 293 294 295 296 297
	udelay (400);
	mtdcr (memcfga, mem_ecccf);
	tmp = mfdcr (memcfgd);
	tmp |= 0x00800000;
	mtdcr (memcfgd, tmp);
	udelay (400);
W
wdenk 已提交
298 299
	printf ("enabled.\n");
	return (0);
W
wdenk 已提交
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
}

/* ------------------------------------------------------------------------- */
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)
W
wdenk 已提交
321
	{
W
wdenk 已提交
322
		setenv (Things[thing].envname, Things[thing].dhcpvalue);
W
wdenk 已提交
323
	}
W
Wolfgang Denk 已提交
324
	return ((u8 *)(Things[thing].dhcpvalue));
W
wdenk 已提交
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
}

/* ------------------------------------------------------------------------- */
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) {
W
wdenk 已提交
358 359 360
					if (!(retval = dhcp_env_update (thing, sub_op))) {
						return NULL;
					}
W
wdenk 已提交
361 362 363 364 365 366 367 368 369 370
			    }
			}
		}
	} else {
		for (thing = 0; thing < N_THINGS; thing++) {
			if (*pop == Things[thing].dhcp_option)
				if (!(retval = dhcp_env_update (thing, pop)))
					return NULL;
		}
	}
W
wdenk 已提交
371
	return (pop);
W
wdenk 已提交
372
}