1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <common.h>
25#include <asm/processor.h>
26#include <asm/ppc4xx-i2c.h>
27#include <command.h>
28#include <rtc.h>
29#include <post.h>
30#include <net.h>
31#include <malloc.h>
32
33#define L1_MEMSIZE (32*1024*1024)
34
35
36#define DHCP_ROUTER 3
37#define DHCP_NETMASK 1
38#define DHCP_BOOTFILE 67
39#define DHCP_ROOTPATH 17
40#define DHCP_HOSTNAME 12
41
42
43
44
45
46
47
48
49#define DHCP_L1_INITRD 224
50
51
52
53
54
55
56
57
58
59#define DHCP_VENDOR_SPECX 43
60#define DHCP_VX_INITRD 3
61#define DHCP_VX_BOOTCMD 4
62#define DHCP_VX_BOOTARGS 5
63#define DHCP_VX_ROOTDEV 6
64#define DHCP_VX_FROMFLASH 7
65#define DHCP_VX_BOOTSCRIPT 8
66#define DHCP_VX_RCFILE 9
67#define DHCP_VX_MAGIC 10
68
69
70
71
72
73
74
75
76
77typedef struct dhcp_item_s {
78 u8 dhcp_option;
79 u8 dhcp_vendor_option;
80 char *dhcpvalue;
81 char *envname;
82} dhcp_item_t;
83static dhcp_item_t Things[] = {
84 {DHCP_ROUTER, 0, NULL, "gateway"},
85 {DHCP_NETMASK, 0, NULL, "netmask"},
86 {DHCP_BOOTFILE, 0, NULL, "bootfile"},
87 {DHCP_ROOTPATH, 0, NULL, "rootpath"},
88 {DHCP_HOSTNAME, 0, NULL, "hostname"},
89 {DHCP_L1_INITRD, 0, NULL, "initrd"},
90
91 {DHCP_VENDOR_SPECX, DHCP_VX_INITRD, NULL, "initrd"},
92 {DHCP_VENDOR_SPECX, DHCP_VX_BOOTCMD, NULL, "bootcmd"},
93 {DHCP_VENDOR_SPECX, DHCP_VX_FROMFLASH, NULL, "fromflash"},
94 {DHCP_VENDOR_SPECX, DHCP_VX_BOOTSCRIPT, NULL, "bootscript"},
95 {DHCP_VENDOR_SPECX, DHCP_VX_RCFILE, NULL, "rcfile"},
96 {DHCP_VENDOR_SPECX, DHCP_VX_BOOTARGS, NULL, "xbootargs"},
97 {DHCP_VENDOR_SPECX, DHCP_VX_ROOTDEV, NULL, NULL},
98 {DHCP_VENDOR_SPECX, DHCP_VX_MAGIC, NULL, NULL}
99};
100
101#define N_THINGS ((sizeof(Things))/(sizeof(dhcp_item_t)))
102
103extern char bootscript[];
104
105
106
107
108
109static void init_sdram (void);
110
111
112int board_early_init_f (void)
113{
114
115 init_sdram ();
116 mtdcr (UIC0SR, 0xFFFFFFFF);
117 mtdcr (UIC0ER, 0x00000000);
118 mtdcr (UIC0CR, 0x00000020);
119 mtdcr (UIC0PR, 0xFFFFFFE0);
120 mtdcr (UIC0TR, 0x10000000);
121 mtdcr (UIC0VCR, 0x00000001);
122 mtdcr (UIC0SR, 0xFFFFFFFF);
123 return 0;
124}
125
126
127int checkboard (void)
128{
129 return (0);
130}
131
132
133
134int misc_init_r (void)
135{
136 char *s, *e;
137 image_header_t *hdr;
138 time_t timestamp;
139 struct rtc_time tm;
140 char bootcmd[32];
141
142 hdr = (image_header_t *) (CONFIG_SYS_MONITOR_BASE - image_get_header_size ());
143#if defined(CONFIG_FIT)
144 if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) {
145 puts ("Non legacy image format not supported\n");
146 return -1;
147 }
148#endif
149
150 timestamp = (time_t)image_get_time (hdr);
151 to_tm (timestamp, &tm);
152 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);
153
154#define FACTORY_SETTINGS 0xFFFC0000
155 if ((s = getenv ("ethaddr")) == NULL) {
156 e = (char *) (FACTORY_SETTINGS);
157 if (*(e + 0) != '0'
158 || *(e + 1) != '0'
159 || *(e + 2) != ':'
160 || *(e + 3) != '4' || *(e + 4) != '0' || *(e + 17) != '\0') {
161 printf ("No valid MAC address in flash location 0x3C0000!\n");
162 } else {
163 printf ("Factory MAC: %s\n", e);
164 setenv ("ethaddr", e);
165 }
166 }
167 sprintf (bootcmd,"source %X",(unsigned)bootscript);
168 setenv ("bootcmd", bootcmd);
169 return (0);
170}
171
172
173
174int rtc_get (struct rtc_time *tmp)
175{
176 return 0;
177}
178int rtc_set (struct rtc_time *tmp)
179{
180 return 0;
181}
182void rtc_reset (void)
183{
184 return;
185}
186
187
188
189
190static void init_sdram (void)
191{
192 unsigned long tmp;
193
194
195 mtdcr (SDRAM0_CFGADDR, SDRAM0_B0CR);
196 mtdcr (SDRAM0_CFGDATA, 0x00062001);
197
198
199
200
201
202
203
204
205
206
207
208
209 mtdcr (SDRAM0_CFGADDR, SDRAM0_TR);
210 mtdcr (SDRAM0_CFGDATA, 0x0086400D);
211
212
213 mtdcr (SDRAM0_CFGADDR, SDRAM0_RTR);
214 mtdcr (SDRAM0_CFGDATA, 0x05F00000);
215 udelay (200);
216
217
218 mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
219 mtdcr (SDRAM0_CFGDATA, 0x90800000);
220 udelay (200);
221
222
223 udelay (200);
224 mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
225 tmp = mfdcr (SDRAM0_CFGDATA);
226 tmp &= 0xff0fffff;
227 mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
228 mtdcr (SDRAM0_CFGDATA, tmp);
229
230 return;
231}
232
233extern int memory_post_test (int flags);
234
235int testdram (void)
236{
237 unsigned long tmp;
238 uint *pstart = (uint *) 0x00000000;
239 uint *pend = (uint *) L1_MEMSIZE;
240 uint *p;
241
242 if (getenv_f("booted",NULL,0) <= 0)
243 {
244 printf ("testdram..");
245
246 for (p = pstart; p < pend; p++)
247 *p = 0xaaaaaaaa;
248 for (p = pstart; p < pend; p++) {
249 if (*p != 0xaaaaaaaa) {
250 printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
251 (uint) p, *p, 0xaaaaaaaa);
252 return 1;
253 }
254 }
255
256 for (p = pstart; p < pend; p++)
257 *p = 0x55555555;
258 for (p = pstart; p < pend; p++) {
259 if (*p != 0x55555555) {
260 printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
261 (uint) p, *p, 0x55555555);
262 return 1;
263 }
264 }
265
266 for (p = pstart; p < pend; p++)
267 *p = (unsigned)p;
268 for (p = pstart; p < pend; p++) {
269 if (*p != (unsigned)p) {
270 printf ("SDRAM test fails at: %08x, was %08x expected %08x\n",
271 (uint) p, *p, (uint)p);
272 return 1;
273 }
274 }
275 printf ("Success. ");
276 }
277 printf ("Enable ECC..");
278
279 mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
280 tmp = (mfdcr (SDRAM0_CFGDATA) & ~0xFFE00000) | 0x90800000;
281 mtdcr (SDRAM0_CFGADDR, SDRAM0_CFG);
282 mtdcr (SDRAM0_CFGDATA, tmp);
283 udelay (600);
284 for (p = (unsigned long) 0; ((unsigned long) p < L1_MEMSIZE); *p++ = 0L)
285 ;
286 udelay (400);
287 mtdcr (SDRAM0_CFGADDR, SDRAM0_ECCCFG);
288 tmp = mfdcr (SDRAM0_CFGDATA);
289 tmp |= 0x00800000;
290 mtdcr (SDRAM0_CFGDATA, tmp);
291 udelay (400);
292 printf ("enabled.\n");
293 return (0);
294}
295
296
297static u8 *dhcp_env_update (u8 thing, u8 * pop)
298{
299 u8 i, oplen;
300
301 oplen = *(pop + 1);
302
303 if ((Things[thing].dhcpvalue = malloc (oplen)) == NULL) {
304 printf ("Whoops! failed to malloc space for DHCP thing %s\n",
305 Things[thing].envname);
306 return NULL;
307 }
308 for (i = 0; (i < oplen); i++)
309 if ((*(Things[thing].dhcpvalue + i) = *(pop + 2 + i)) == ' ')
310 break;
311 *(Things[thing].dhcpvalue + i) = '\0';
312
313
314 if (Things[thing].envname)
315 {
316 setenv (Things[thing].envname, Things[thing].dhcpvalue);
317 }
318 return ((u8 *)(Things[thing].dhcpvalue));
319}
320
321
322u8 *dhcp_vendorex_prep (u8 * e)
323{
324 u8 thing;
325
326
327 *e++ = 55;
328 *e++ = N_THINGS;
329 for (thing = 0; thing < N_THINGS; thing++)
330 *e++ = Things[thing].dhcp_option;
331 *e++ = 255;
332
333 return e;
334}
335
336
337
338u8 *dhcp_vendorex_proc (u8 * pop)
339{
340 u8 oplen, *sub_op, sub_oplen, *retval;
341 u8 thing = 0;
342
343 retval = NULL;
344 oplen = *(pop + 1);
345
346 if (*pop == DHCP_VENDOR_SPECX) {
347 for (sub_op = pop + 2;
348 oplen && (sub_oplen = *(sub_op + 1));
349 oplen -= sub_oplen, sub_op += (sub_oplen + 2)) {
350 for (thing = 0; thing < N_THINGS; thing++) {
351 if (*sub_op == Things[thing].dhcp_vendor_option) {
352 if (!(retval = dhcp_env_update (thing, sub_op))) {
353 return NULL;
354 }
355 }
356 }
357 }
358 } else {
359 for (thing = 0; thing < N_THINGS; thing++) {
360 if (*pop == Things[thing].dhcp_option)
361 if (!(retval = dhcp_env_update (thing, pop)))
362 return NULL;
363 }
364 }
365 return (pop);
366}
367