blob: f5dfba4aacfd26de41ba40d5d657ae29a33d9224 [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
2 * (C) Copyright 2000
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
25#include <asm/processor.h>
26#include <405gp_i2c.h>
27#include <command.h>
28#include <cmd_nvedit.h>
29#include <cmd_bootm.h>
30#include <rtc.h>
31#include <net.h>
32#include <malloc.h>
33
34#define L1_MEMSIZE (32*1024*1024)
35
36/* the std. DHCP stufff */
37#define DHCP_ROUTER 3
38#define DHCP_NETMASK 1
39#define DHCP_BOOTFILE 67
40#define DHCP_ROOTPATH 17
41#define DHCP_HOSTNAME 12
42
43/* some extras used by CRAY
44 *
45 * on the server this looks like:
46 *
47 * option L1-initrd-image code 224 = string;
48 * option L1-initrd-image "/opt/craysv2/craymcu/l1/flash/initrd.image"
49 */
50#define DHCP_L1_INITRD 224
51
52/* new, [better?] way via official vendor-extensions, defining an option
53 * space.
54 * on the server this looks like:
55 *
56 * option space U-Boot;
57 * option U-Boot.initrd code 3 = string;
58 * option U-Boot.bootcmd code 4 = string;
59 * option U-Boot.bootflags code 5 = string;
60 * option U-Boot.rootdev code 6 = string;
61 */
62#define DHCP_VENDOR_SPECX 43
63#define DHCP_VX_INITRD 3
64#define DHCP_VX_BOOTCMD 4
65#define DHCP_VX_BOOTFLAGS 5
66#define DHCP_VX_ROOTDEV 6
67
68/* Things DHCP server can tellme about. If there's no flash address, then
69 * they dont participate in 'update' to flash, and we force their values
70 * back to '0' every boot to be sure to get them fresh from DHCP. Yes, I
71 * know this is a pain...
72 *
73 * If I get no bootfile, boot from flash. If rootpath, use that. If no
74 * rootpath use initrd in flash.
75 */
76typedef struct dhcp_item_s {
77 u8 dhcp_option;
78 u8 dhcp_vendor_option;
79 char *dhcpvalue;
80 char *envname;
81} dhcp_item_t;
82static dhcp_item_t Things[] = {
83 {DHCP_ROUTER, 0, NULL, "gateway"},
84 {DHCP_NETMASK, 0, NULL, "netmask"},
85 {DHCP_BOOTFILE, 0, NULL, "bootfile"},
86 {DHCP_ROOTPATH, 0, NULL, "rootpath"},
87 {DHCP_HOSTNAME, 0, NULL, "hostname"},
88 {DHCP_L1_INITRD, 0, NULL, "initrd"},
89/* and the other way.. */
90 {DHCP_VENDOR_SPECX, DHCP_VX_INITRD, NULL, "initrd"},
91 {DHCP_VENDOR_SPECX, DHCP_VX_BOOTCMD, NULL, "bootcmd"},
92 {DHCP_VENDOR_SPECX, DHCP_VX_BOOTFLAGS, NULL, NULL},
93 {DHCP_VENDOR_SPECX, DHCP_VX_ROOTDEV, NULL, NULL},
94};
95
96#define N_THINGS ((sizeof(Things))/(sizeof(dhcp_item_t)))
97
98static void init_ecc_sdram (void);
99
100/* ------------------------------------------------------------------------- */
101int board_pre_init (void)
102{
103 init_ecc_sdram ();
104 mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
105 mtdcr (uicer, 0x00000000); /* disable all ints */
106 mtdcr (uiccr, 0x00000020); /* set all but FPGA SMI to be non-critical */
107 mtdcr (uicpr, 0xFFFFFFE0); /* set int polarities */
108 mtdcr (uictr, 0x10000000); /* set int trigger levels */
109 mtdcr (uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */
110 mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */
111 return 0;
112}
113
114/* ------------------------------------------------------------------------- */
115int checkboard (void)
116{
117 return (0);
118}
119
120/* ------------------------------------------------------------------------- */
121int misc_init_r (void)
122{
123 unsigned char *s, *e;
124 image_header_t *hdr;
125 time_t timestamp;
126 struct rtc_time tm;
127
128 hdr = (image_header_t *) (CFG_MONITOR_BASE - sizeof (image_header_t));
129 timestamp = (time_t) hdr->ih_time;
130 to_tm (timestamp, &tm);
131 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);
132
133#define FACTORY_SETTINGS 0xFFFC0000
134 if ((s = getenv ("ethaddr")) == NULL) {
135 e = (unsigned char *) (FACTORY_SETTINGS);
136 if (*(e + 0) != '0'
137 || *(e + 1) != '0'
138 || *(e + 2) != ':'
139 || *(e + 3) != '4' || *(e + 4) != '0' || *(e + 17) != '\0') {
140 printf ("No valid MAC address in flash location 0x3C0000!\n");
141 } else {
142 printf ("Factory MAC: %s\n", e);
143 setenv ("ethaddr", e);
144 }
145 }
146 return (0);
147}
148
149/* ------------------------------------------------------------------------- */
150long int initdram (int board_type)
151{
152 return (L1_MEMSIZE);
153}
154
155/* ------------------------------------------------------------------------- */
156/* stubs so we can print dates w/o any nvram RTC.*/
157void rtc_get (struct rtc_time *tmp)
158{
159 return;
160}
161void rtc_set (struct rtc_time *tmp)
162{
163 return;
164}
165void rtc_reset (void)
166{
167 return;
168}
169
170/* ------------------------------------------------------------------------- */
171/* Do sdram bank init in C so I can read it..
172 */
173static void init_ecc_sdram (void)
174{
175 unsigned long tmp, *p;
176
177 /* write SDRAM bank 0 register */
178 mtdcr (memcfga, mem_mb0cf);
179 mtdcr (memcfgd, 0x00062001);
180
181/* Set the SDRAM Timing reg, SDTR1 and the refresh timer reg, RTR. */
182/* To set the appropriate timings, we need to know the SDRAM speed. */
183/* We can use the PLB speed since the SDRAM speed is the same as */
184/* the PLB speed. The PLB speed is the FBK divider times the */
185/* 405GP reference clock, which on the L1 is 25Mhz. */
186/* Thus, if FBK div is 2, SDRAM is 50Mhz; if FBK div is 3, SDRAM is */
187/* 150Mhz; if FBK is 3, SDRAM is 150Mhz. */
188
189 /* divisor = ((mfdcr(strap)>> 28) & 0x3); */
190
191/* write SDRAM timing for 100Mhz. */
192 mtdcr (memcfga, mem_sdtr1);
193 mtdcr (memcfgd, 0x0086400D);
194
195/* write SDRAM refresh interval register */
196 mtdcr (memcfga, mem_rtr);
197 mtdcr (memcfgd, 0x05F00000);
198 udelay (200);
199
200/* sdram controller.*/
201 mtdcr (memcfga, mem_mcopt1);
202 mtdcr (memcfgd, 0x90800000);
203 udelay (200);
204
205/* disable ECC on all banks */
206 mtdcr (memcfga, mem_ecccf);
207 tmp = mfdcr (memcfgd);
208 tmp &= 0xff0fffff;
209 mtdcr (memcfga, mem_ecccf);
210 mtdcr (memcfgd, tmp);
211
212/* set up SDRAM Controller with ECC enabled */
213 mtdcr (memcfga, mem_mcopt1);
214 tmp = (mfdcr (memcfgd) & ~0xFFE00000) | 0x90800000;
215 mtdcr (memcfga, mem_mcopt1);
216 mtdcr (memcfgd, tmp);
217 udelay (600);
218
219/* fill all the memory */
220 for (p = (unsigned long) 0; ((unsigned long) p < L1_MEMSIZE);
221 *p++ = 0L);
222 udelay (400);
223 mtdcr (memcfga, mem_ecccf);
224 tmp = mfdcr (memcfgd);
225
226/* enable ECC on bank 0 */
227 tmp |= 0x00800000;
228 mtdcr (memcfgd, tmp);
229 udelay (400);
230
231 return;
232}
233
234/* ------------------------------------------------------------------------- */
235static u8 *dhcp_env_update (u8 thing, u8 * pop)
236{
237 u8 i, oplen;
238
239 oplen = *(pop + 1);
240
241 if ((Things[thing].dhcpvalue = malloc (oplen)) == NULL) {
242 printf ("Whoops! failed to malloc space for DHCP thing %s\n",
243 Things[thing].envname);
244 return NULL;
245 }
246 for (i = 0; (i < oplen); i++)
247 if ((*(Things[thing].dhcpvalue + i) = *(pop + 2 + i)) == ' ')
248 break;
249 *(Things[thing].dhcpvalue + i) = '\0';
250
251/* set env. */
252 if (Things[thing].envname)
253 setenv (Things[thing].envname, Things[thing].dhcpvalue);
254 return (Things[thing].dhcpvalue);
255}
256
257/* ------------------------------------------------------------------------- */
258u8 *dhcp_vendorex_prep (u8 * e)
259{
260 u8 thing;
261
262/* ask for the things I want. */
263 *e++ = 55; /* Parameter Request List */
264 *e++ = N_THINGS;
265 for (thing = 0; thing < N_THINGS; thing++)
266 *e++ = Things[thing].dhcp_option;
267 *e++ = 255;
268
269 return e;
270}
271
272/* ------------------------------------------------------------------------- */
273/* .. return NULL means it wasnt mine, non-null means I got it..*/
274u8 *dhcp_vendorex_proc (u8 * pop)
275{
276 u8 oplen, *sub_op, sub_oplen, *retval;
277 u8 thing = 0;
278
279 retval = NULL;
280 oplen = *(pop + 1);
281/* if pop is vender spec indicator, there are sub-options. */
282 if (*pop == DHCP_VENDOR_SPECX) {
283 for (sub_op = pop + 2;
284 oplen && (sub_oplen = *(sub_op + 1));
285 oplen -= sub_oplen, sub_op += (sub_oplen + 2)) {
286 for (thing = 0; thing < N_THINGS; thing++) {
287 if (*sub_op == Things[thing].dhcp_vendor_option) {
288 if (!(retval = dhcp_env_update (thing, sub_op))) {
289 return NULL;
290 }
291 }
292 }
293 }
294 } else {
295 for (thing = 0; thing < N_THINGS; thing++) {
296 if (*pop == Things[thing].dhcp_option)
297 if (!(retval = dhcp_env_update (thing, pop)))
298 return NULL;
299 }
300 }
301 return (thing >= N_THINGS ? NULL : pop);
302}