]>
Commit | Line | Data |
---|---|---|
47d1a6e1 WD |
1 | /* |
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> | |
7f70e853 | 30 | #include <cmd_boot.h> |
47d1a6e1 | 31 | #include <rtc.h> |
7f70e853 | 32 | #include <post.h> |
47d1a6e1 WD |
33 | #include <net.h> |
34 | #include <malloc.h> | |
35 | ||
36 | #define L1_MEMSIZE (32*1024*1024) | |
37 | ||
38 | /* the std. DHCP stufff */ | |
39 | #define DHCP_ROUTER 3 | |
40 | #define DHCP_NETMASK 1 | |
41 | #define DHCP_BOOTFILE 67 | |
42 | #define DHCP_ROOTPATH 17 | |
43 | #define DHCP_HOSTNAME 12 | |
44 | ||
45 | /* some extras used by CRAY | |
46 | * | |
47 | * on the server this looks like: | |
48 | * | |
49 | * option L1-initrd-image code 224 = string; | |
50 | * option L1-initrd-image "/opt/craysv2/craymcu/l1/flash/initrd.image" | |
51 | */ | |
52 | #define DHCP_L1_INITRD 224 | |
53 | ||
54 | /* new, [better?] way via official vendor-extensions, defining an option | |
55 | * space. | |
56 | * on the server this looks like: | |
57 | * | |
7f70e853 WD |
58 | * option space CRAYL1; |
59 | * option CRAYL1.initrd code 3 = string; | |
60 | * ..etc... | |
47d1a6e1 WD |
61 | */ |
62 | #define DHCP_VENDOR_SPECX 43 | |
63 | #define DHCP_VX_INITRD 3 | |
64 | #define DHCP_VX_BOOTCMD 4 | |
7f70e853 | 65 | #define DHCP_VX_BOOTARGS 5 |
47d1a6e1 | 66 | #define DHCP_VX_ROOTDEV 6 |
7f70e853 WD |
67 | #define DHCP_VX_FROMFLASH 7 |
68 | #define DHCP_VX_BOOTSCRIPT 8 | |
69 | #define DHCP_VX_RCFILE 9 | |
70 | #define DHCP_VX_MAGIC 10 | |
47d1a6e1 WD |
71 | |
72 | /* Things DHCP server can tellme about. If there's no flash address, then | |
73 | * they dont participate in 'update' to flash, and we force their values | |
74 | * back to '0' every boot to be sure to get them fresh from DHCP. Yes, I | |
75 | * know this is a pain... | |
76 | * | |
77 | * If I get no bootfile, boot from flash. If rootpath, use that. If no | |
78 | * rootpath use initrd in flash. | |
79 | */ | |
80 | typedef struct dhcp_item_s { | |
81 | u8 dhcp_option; | |
82 | u8 dhcp_vendor_option; | |
83 | char *dhcpvalue; | |
84 | char *envname; | |
85 | } dhcp_item_t; | |
86 | static dhcp_item_t Things[] = { | |
87 | {DHCP_ROUTER, 0, NULL, "gateway"}, | |
88 | {DHCP_NETMASK, 0, NULL, "netmask"}, | |
89 | {DHCP_BOOTFILE, 0, NULL, "bootfile"}, | |
90 | {DHCP_ROOTPATH, 0, NULL, "rootpath"}, | |
91 | {DHCP_HOSTNAME, 0, NULL, "hostname"}, | |
92 | {DHCP_L1_INITRD, 0, NULL, "initrd"}, | |
93 | /* and the other way.. */ | |
94 | {DHCP_VENDOR_SPECX, DHCP_VX_INITRD, NULL, "initrd"}, | |
95 | {DHCP_VENDOR_SPECX, DHCP_VX_BOOTCMD, NULL, "bootcmd"}, | |
7f70e853 WD |
96 | {DHCP_VENDOR_SPECX, DHCP_VX_FROMFLASH, NULL, "fromflash"}, |
97 | {DHCP_VENDOR_SPECX, DHCP_VX_BOOTSCRIPT, NULL, "bootscript"}, | |
98 | {DHCP_VENDOR_SPECX, DHCP_VX_RCFILE, NULL, "rcfile"}, | |
99 | {DHCP_VENDOR_SPECX, DHCP_VX_BOOTARGS, NULL, "xbootargs"}, | |
47d1a6e1 | 100 | {DHCP_VENDOR_SPECX, DHCP_VX_ROOTDEV, NULL, NULL}, |
7f70e853 | 101 | {DHCP_VENDOR_SPECX, DHCP_VX_MAGIC, NULL, NULL} |
47d1a6e1 WD |
102 | }; |
103 | ||
104 | #define N_THINGS ((sizeof(Things))/(sizeof(dhcp_item_t))) | |
105 | ||
7f70e853 WD |
106 | extern char bootscript[]; |
107 | ||
108 | /* Here is the boot logic as HUSH script. Overridden by any TFP provided | |
109 | * bootscript file. | |
110 | */ | |
111 | ||
112 | static void init_sdram (void); | |
47d1a6e1 WD |
113 | |
114 | /* ------------------------------------------------------------------------- */ | |
115 | int board_pre_init (void) | |
116 | { | |
7f70e853 WD |
117 | /* Running from ROM: global data is still READONLY */ |
118 | init_sdram (); | |
47d1a6e1 WD |
119 | mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */ |
120 | mtdcr (uicer, 0x00000000); /* disable all ints */ | |
121 | mtdcr (uiccr, 0x00000020); /* set all but FPGA SMI to be non-critical */ | |
122 | mtdcr (uicpr, 0xFFFFFFE0); /* set int polarities */ | |
123 | mtdcr (uictr, 0x10000000); /* set int trigger levels */ | |
124 | mtdcr (uicvcr, 0x00000001); /* set vect base=0,INT0 highest priority */ | |
125 | mtdcr (uicsr, 0xFFFFFFFF); /* clear all ints */ | |
126 | return 0; | |
127 | } | |
128 | ||
129 | /* ------------------------------------------------------------------------- */ | |
130 | int checkboard (void) | |
131 | { | |
132 | return (0); | |
133 | } | |
7f70e853 | 134 | /* ------------------------------------------------------------------------- */ |
47d1a6e1 WD |
135 | |
136 | /* ------------------------------------------------------------------------- */ | |
137 | int misc_init_r (void) | |
138 | { | |
139 | unsigned char *s, *e; | |
140 | image_header_t *hdr; | |
141 | time_t timestamp; | |
142 | struct rtc_time tm; | |
7f70e853 | 143 | char bootcmd[32]; |
47d1a6e1 WD |
144 | |
145 | hdr = (image_header_t *) (CFG_MONITOR_BASE - sizeof (image_header_t)); | |
146 | timestamp = (time_t) hdr->ih_time; | |
147 | to_tm (timestamp, &tm); | |
148 | 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); | |
149 | ||
150 | #define FACTORY_SETTINGS 0xFFFC0000 | |
151 | if ((s = getenv ("ethaddr")) == NULL) { | |
152 | e = (unsigned char *) (FACTORY_SETTINGS); | |
153 | if (*(e + 0) != '0' | |
154 | || *(e + 1) != '0' | |
155 | || *(e + 2) != ':' | |
156 | || *(e + 3) != '4' || *(e + 4) != '0' || *(e + 17) != '\0') { | |
157 | printf ("No valid MAC address in flash location 0x3C0000!\n"); | |
158 | } else { | |
159 | printf ("Factory MAC: %s\n", e); | |
160 | setenv ("ethaddr", e); | |
161 | } | |
162 | } | |
7f70e853 WD |
163 | sprintf (bootcmd,"autoscript %X",(unsigned)bootscript); |
164 | setenv ("bootcmd", bootcmd); | |
47d1a6e1 WD |
165 | return (0); |
166 | } | |
167 | ||
168 | /* ------------------------------------------------------------------------- */ | |
169 | long int initdram (int board_type) | |
170 | { | |
171 | return (L1_MEMSIZE); | |
172 | } | |
173 | ||
174 | /* ------------------------------------------------------------------------- */ | |
175 | /* stubs so we can print dates w/o any nvram RTC.*/ | |
176 | void rtc_get (struct rtc_time *tmp) | |
177 | { | |
178 | return; | |
179 | } | |
180 | void rtc_set (struct rtc_time *tmp) | |
181 | { | |
182 | return; | |
183 | } | |
184 | void rtc_reset (void) | |
185 | { | |
186 | return; | |
187 | } | |
188 | ||
189 | /* ------------------------------------------------------------------------- */ | |
7f70e853 | 190 | /* Do sdram bank init in C so I can read it..no console to print to yet! |
47d1a6e1 | 191 | */ |
7f70e853 | 192 | static void init_sdram (void) |
47d1a6e1 | 193 | { |
7f70e853 | 194 | unsigned long tmp; |
47d1a6e1 WD |
195 | |
196 | /* write SDRAM bank 0 register */ | |
197 | mtdcr (memcfga, mem_mb0cf); | |
198 | mtdcr (memcfgd, 0x00062001); | |
199 | ||
200 | /* Set the SDRAM Timing reg, SDTR1 and the refresh timer reg, RTR. */ | |
201 | /* To set the appropriate timings, we need to know the SDRAM speed. */ | |
202 | /* We can use the PLB speed since the SDRAM speed is the same as */ | |
203 | /* the PLB speed. The PLB speed is the FBK divider times the */ | |
204 | /* 405GP reference clock, which on the L1 is 25Mhz. */ | |
205 | /* Thus, if FBK div is 2, SDRAM is 50Mhz; if FBK div is 3, SDRAM is */ | |
206 | /* 150Mhz; if FBK is 3, SDRAM is 150Mhz. */ | |
207 | ||
208 | /* divisor = ((mfdcr(strap)>> 28) & 0x3); */ | |
209 | ||
210 | /* write SDRAM timing for 100Mhz. */ | |
211 | mtdcr (memcfga, mem_sdtr1); | |
212 | mtdcr (memcfgd, 0x0086400D); | |
213 | ||
214 | /* write SDRAM refresh interval register */ | |
215 | mtdcr (memcfga, mem_rtr); | |
216 | mtdcr (memcfgd, 0x05F00000); | |
217 | udelay (200); | |
218 | ||
219 | /* sdram controller.*/ | |
220 | mtdcr (memcfga, mem_mcopt1); | |
221 | mtdcr (memcfgd, 0x90800000); | |
222 | udelay (200); | |
223 | ||
7f70e853 WD |
224 | /* initially, disable ECC on all banks */ |
225 | udelay (200); | |
47d1a6e1 WD |
226 | mtdcr (memcfga, mem_ecccf); |
227 | tmp = mfdcr (memcfgd); | |
228 | tmp &= 0xff0fffff; | |
229 | mtdcr (memcfga, mem_ecccf); | |
230 | mtdcr (memcfgd, tmp); | |
231 | ||
7f70e853 WD |
232 | return; |
233 | } | |
234 | ||
235 | extern int memory_post_test (int flags); | |
236 | ||
237 | int testdram (void) | |
238 | { | |
239 | unsigned long tmp; | |
240 | uint *pstart = (uint *) 0x00000000; | |
241 | uint *pend = (uint *) L1_MEMSIZE; | |
242 | uint *p; | |
243 | ||
244 | if (getenv_r("booted",NULL,0) <= 0) | |
245 | { | |
246 | printf ("testdram.."); | |
247 | /*AA*/ | |
248 | for (p = pstart; p < pend; p++) | |
249 | *p = 0xaaaaaaaa; | |
250 | for (p = pstart; p < pend; p++) { | |
251 | if (*p != 0xaaaaaaaa) { | |
252 | printf ("SDRAM test fails at: %08x, was %08x expected %08x\n", | |
253 | (uint) p, *p, 0xaaaaaaaa); | |
254 | return 1; | |
255 | } | |
256 | } | |
257 | /*55*/ | |
258 | for (p = pstart; p < pend; p++) | |
259 | *p = 0x55555555; | |
260 | for (p = pstart; p < pend; p++) { | |
261 | if (*p != 0x55555555) { | |
262 | printf ("SDRAM test fails at: %08x, was %08x expected %08x\n", | |
263 | (uint) p, *p, 0x55555555); | |
264 | return 1; | |
265 | } | |
266 | } | |
267 | /*addr*/ | |
268 | for (p = pstart; p < pend; p++) | |
269 | *p = (unsigned)p; | |
270 | for (p = pstart; p < pend; p++) { | |
271 | if (*p != (unsigned)p) { | |
272 | printf ("SDRAM test fails at: %08x, was %08x expected %08x\n", | |
273 | (uint) p, *p, (uint)p); | |
274 | return 1; | |
275 | } | |
276 | } | |
277 | printf ("Success. "); | |
278 | } | |
279 | printf ("Enable ECC.."); | |
280 | ||
47d1a6e1 WD |
281 | mtdcr (memcfga, mem_mcopt1); |
282 | tmp = (mfdcr (memcfgd) & ~0xFFE00000) | 0x90800000; | |
283 | mtdcr (memcfga, mem_mcopt1); | |
284 | mtdcr (memcfgd, tmp); | |
285 | udelay (600); | |
7f70e853 WD |
286 | for (p = (unsigned long) 0; ((unsigned long) p < L1_MEMSIZE); *p++ = 0L) |
287 | ; | |
47d1a6e1 WD |
288 | udelay (400); |
289 | mtdcr (memcfga, mem_ecccf); | |
290 | tmp = mfdcr (memcfgd); | |
47d1a6e1 WD |
291 | tmp |= 0x00800000; |
292 | mtdcr (memcfgd, tmp); | |
293 | udelay (400); | |
7f70e853 WD |
294 | printf ("enabled.\n"); |
295 | return (0); | |
47d1a6e1 WD |
296 | } |
297 | ||
298 | /* ------------------------------------------------------------------------- */ | |
299 | static u8 *dhcp_env_update (u8 thing, u8 * pop) | |
300 | { | |
301 | u8 i, oplen; | |
302 | ||
303 | oplen = *(pop + 1); | |
304 | ||
305 | if ((Things[thing].dhcpvalue = malloc (oplen)) == NULL) { | |
306 | printf ("Whoops! failed to malloc space for DHCP thing %s\n", | |
307 | Things[thing].envname); | |
308 | return NULL; | |
309 | } | |
310 | for (i = 0; (i < oplen); i++) | |
311 | if ((*(Things[thing].dhcpvalue + i) = *(pop + 2 + i)) == ' ') | |
312 | break; | |
313 | *(Things[thing].dhcpvalue + i) = '\0'; | |
314 | ||
315 | /* set env. */ | |
316 | if (Things[thing].envname) | |
7f70e853 | 317 | { |
47d1a6e1 | 318 | setenv (Things[thing].envname, Things[thing].dhcpvalue); |
7f70e853 | 319 | } |
47d1a6e1 WD |
320 | return (Things[thing].dhcpvalue); |
321 | } | |
322 | ||
323 | /* ------------------------------------------------------------------------- */ | |
324 | u8 *dhcp_vendorex_prep (u8 * e) | |
325 | { | |
326 | u8 thing; | |
327 | ||
328 | /* ask for the things I want. */ | |
329 | *e++ = 55; /* Parameter Request List */ | |
330 | *e++ = N_THINGS; | |
331 | for (thing = 0; thing < N_THINGS; thing++) | |
332 | *e++ = Things[thing].dhcp_option; | |
333 | *e++ = 255; | |
334 | ||
335 | return e; | |
336 | } | |
337 | ||
338 | /* ------------------------------------------------------------------------- */ | |
339 | /* .. return NULL means it wasnt mine, non-null means I got it..*/ | |
340 | u8 *dhcp_vendorex_proc (u8 * pop) | |
341 | { | |
342 | u8 oplen, *sub_op, sub_oplen, *retval; | |
343 | u8 thing = 0; | |
344 | ||
345 | retval = NULL; | |
346 | oplen = *(pop + 1); | |
347 | /* if pop is vender spec indicator, there are sub-options. */ | |
348 | if (*pop == DHCP_VENDOR_SPECX) { | |
349 | for (sub_op = pop + 2; | |
350 | oplen && (sub_oplen = *(sub_op + 1)); | |
351 | oplen -= sub_oplen, sub_op += (sub_oplen + 2)) { | |
352 | for (thing = 0; thing < N_THINGS; thing++) { | |
353 | if (*sub_op == Things[thing].dhcp_vendor_option) { | |
7f70e853 WD |
354 | if (!(retval = dhcp_env_update (thing, sub_op))) { |
355 | return NULL; | |
356 | } | |
47d1a6e1 WD |
357 | } |
358 | } | |
359 | } | |
360 | } else { | |
361 | for (thing = 0; thing < N_THINGS; thing++) { | |
362 | if (*pop == Things[thing].dhcp_option) | |
363 | if (!(retval = dhcp_env_update (thing, pop))) | |
364 | return NULL; | |
365 | } | |
366 | } | |
7f70e853 | 367 | return (pop); |
47d1a6e1 | 368 | } |