blob: 118d81c7f29676fdfd2b4e8de786ce7b75c6cc09 [file] [log] [blame]
Stefan Roesea4c8d132006-06-02 16:18:04 +02001/*
2 * (C) Copyright 2006
3 * Stefan Roese, DENX Software Engineering, sr@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>
Stefan Roeseb36df562010-09-09 19:18:00 +020025#include <asm/ppc4xx.h>
Heiko Schocher566a4942007-06-22 19:11:54 +020026#include <malloc.h>
27#include <command.h>
28#include <crc.h>
Stefan Roesea4c8d132006-06-02 16:18:04 +020029#include <asm/processor.h>
30#include <spd_sdram.h>
Heiko Schocher566a4942007-06-22 19:11:54 +020031#include <status_led.h>
32#include <sha1.h>
Heiko Schocherf98984c2007-08-28 17:39:14 +020033#include <asm/io.h>
Wolfgang Denkd2567be2009-03-28 20:16:16 +010034#include <net.h>
Stefan Roesea4c8d132006-06-02 16:18:04 +020035
36DECLARE_GLOBAL_DATA_PTR;
37
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020038extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
Stefan Roesea4c8d132006-06-02 16:18:04 +020039
Heiko Schocher566a4942007-06-22 19:11:54 +020040unsigned char sha1_checksum[SHA1_SUM_LEN];
41
42/* swap 4 Bits (Bit0 = Bit3, Bit1 = Bit2, Bit2 = Bit1 and Bit3 = Bit0) */
43unsigned char swapbits[16] = {0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
44 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf};
45
46static void set_leds (int val)
Stefan Roesea4c8d132006-06-02 16:18:04 +020047{
Heiko Schocher566a4942007-06-22 19:11:54 +020048 out32(GPIO0_OR, (in32 (GPIO0_OR) & ~0x78000000) | (val << 27));
Stefan Roesea4c8d132006-06-02 16:18:04 +020049}
50
Heiko Schocher566a4942007-06-22 19:11:54 +020051#define GET_LEDS ((in32 (GPIO0_OR) & 0x78000000) >> 27)
52
53void __led_init (led_id_t mask, int state)
54{
55 int val = GET_LEDS;
56
57 if (state == STATUS_LED_ON)
58 val |= mask;
59 else
60 val &= ~mask;
61 set_leds (val);
62}
63
64void __led_set (led_id_t mask, int state)
65{
66 int val = GET_LEDS;
67
68 if (state == STATUS_LED_ON)
69 val |= mask;
70 else if (state == STATUS_LED_OFF)
71 val &= ~mask;
72 set_leds (val);
73}
74
75void __led_toggle (led_id_t mask)
76{
77 int val = GET_LEDS;
78
79 val ^= mask;
80 set_leds (val);
81}
82
83static void status_led_blink (void)
84{
85 int i;
86 int val = GET_LEDS;
87
88 /* set all LED which are on, to state BLINKING */
89 for (i = 0; i < 4; i++) {
Heiko Schocher96e1d752007-07-11 18:39:11 +020090 if (val & 0x01) status_led_set (3 - i, STATUS_LED_BLINKING);
91 else status_led_set (3 - i, STATUS_LED_OFF);
92 val = val >> 1;
Heiko Schocher566a4942007-06-22 19:11:54 +020093 }
94}
95
96#if defined(CONFIG_SHOW_BOOT_PROGRESS)
97void show_boot_progress (int val)
98{
99 /* find all valid Codes for val in README */
100 if (val == -30) return;
101 if (val < 0) {
102 /* smthing goes wrong */
103 status_led_blink ();
104 return;
105 }
106 switch (val) {
Simon Glass5dc88712012-01-14 15:24:47 +0000107 case BOOTSTAGE_ID_CHECK_MAGIC:
108 /* validating Image */
109 status_led_set(0, STATUS_LED_OFF);
110 status_led_set(1, STATUS_LED_ON);
111 status_led_set(2, STATUS_LED_ON);
112 break;
113 case BOOTSTAGE_ID_RUN_OS:
114 status_led_set(0, STATUS_LED_ON);
115 status_led_set(1, STATUS_LED_ON);
116 status_led_set(2, STATUS_LED_ON);
117 break;
Heiko Schocher96e1d752007-07-11 18:39:11 +0200118#if 0
Heiko Schocher566a4942007-06-22 19:11:54 +0200119 case 64:
120 /* starting Ethernet configuration */
121 status_led_set (0, STATUS_LED_OFF);
122 status_led_set (1, STATUS_LED_OFF);
123 status_led_set (2, STATUS_LED_ON);
124 break;
Heiko Schocher96e1d752007-07-11 18:39:11 +0200125#endif
Heiko Schocher566a4942007-06-22 19:11:54 +0200126 case 80:
127 /* loading Image */
128 status_led_set (0, STATUS_LED_ON);
129 status_led_set (1, STATUS_LED_OFF);
130 status_led_set (2, STATUS_LED_ON);
131 break;
132 }
133}
134#endif
135
Stefan Roesea4c8d132006-06-02 16:18:04 +0200136int board_early_init_f(void)
137{
138 register uint reg;
139
140 set_leds(0); /* display boot info counter */
141
142 /*--------------------------------------------------------------------
143 * Setup the external bus controller/chip selects
144 *-------------------------------------------------------------------*/
Stefan Roesed1c3b272009-09-09 16:25:29 +0200145 mtdcr(EBC0_CFGADDR, EBC0_CFG);
146 reg = mfdcr(EBC0_CFGDATA);
147 mtdcr(EBC0_CFGDATA, reg | 0x04000000); /* Set ATC */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200148
149 /*--------------------------------------------------------------------
Stefan Roesea47a12b2010-04-15 16:07:28 +0200150 * GPIO's are alreay setup in arch/powerpc/cpu/ppc4xx/cpu_init.c
Stefan Roesea4c8d132006-06-02 16:18:04 +0200151 * via define from board config file.
152 *-------------------------------------------------------------------*/
153
154 /*--------------------------------------------------------------------
155 * Setup the interrupt controller polarities, triggers, etc.
156 *-------------------------------------------------------------------*/
Stefan Roese952e7762009-09-24 09:55:50 +0200157 mtdcr(UIC0SR, 0xffffffff); /* clear all */
158 mtdcr(UIC0ER, 0x00000000); /* disable all */
159 mtdcr(UIC0CR, 0x00000001); /* UIC1 crit is critical */
160 mtdcr(UIC0PR, 0xfffffe1f); /* per ref-board manual */
161 mtdcr(UIC0TR, 0x01c00000); /* per ref-board manual */
162 mtdcr(UIC0VR, 0x00000001); /* int31 highest, base=0x000 */
163 mtdcr(UIC0SR, 0xffffffff); /* clear all */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200164
Stefan Roese952e7762009-09-24 09:55:50 +0200165 mtdcr(UIC1SR, 0xffffffff); /* clear all */
166 mtdcr(UIC1ER, 0x00000000); /* disable all */
167 mtdcr(UIC1CR, 0x00000000); /* all non-critical */
168 mtdcr(UIC1PR, 0xffffe0ff); /* per ref-board manual */
169 mtdcr(UIC1TR, 0x00ffc000); /* per ref-board manual */
170 mtdcr(UIC1VR, 0x00000001); /* int31 highest, base=0x000 */
171 mtdcr(UIC1SR, 0xffffffff); /* clear all */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200172
173 /*--------------------------------------------------------------------
174 * Setup other serial configuration
175 *-------------------------------------------------------------------*/
Stefan Roesed1c3b272009-09-09 16:25:29 +0200176 mfsdr(SDR0_PCI0, reg);
177 mtsdr(SDR0_PCI0, 0x80000000 | reg); /* PCI arbiter enabled */
178 mtsdr(SDR0_PFC0, 0x00000000); /* Pin function: enable GPIO49-63 */
179 mtsdr(SDR0_PFC1, 0x00048000); /* Pin function: UART0 has 4 pins, select IRQ5 */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200180
181 return 0;
182}
183
Heiko Schocher566a4942007-06-22 19:11:54 +0200184#define EEPROM_LEN 256
Mike Frysinger9c150102009-02-11 20:09:52 -0500185static void load_ethaddr(void)
Heiko Schocher566a4942007-06-22 19:11:54 +0200186{
Mike Frysinger9c150102009-02-11 20:09:52 -0500187 int ok_ethaddr, ok_eth1addr;
Heiko Schocher566a4942007-06-22 19:11:54 +0200188 int ret;
Wolfgang Denkd2567be2009-03-28 20:16:16 +0100189 uchar buf[EEPROM_LEN];
Heiko Schocher566a4942007-06-22 19:11:54 +0200190 char *use_eeprom;
191 u16 checksumcrc16 = 0;
192
Mike Frysinger9c150102009-02-11 20:09:52 -0500193 /* If the env is sane, then nothing for us to do */
194 ok_ethaddr = eth_getenv_enetaddr("ethaddr", buf);
195 ok_eth1addr = eth_getenv_enetaddr("eth1addr", buf);
196 if (ok_ethaddr && ok_eth1addr)
197 return;
198
Heiko Schocher566a4942007-06-22 19:11:54 +0200199 /* read the MACs from EEprom */
200 status_led_set (0, STATUS_LED_ON);
201 status_led_set (1, STATUS_LED_ON);
Wolfgang Denkd2567be2009-03-28 20:16:16 +0100202 ret = eeprom_read (CONFIG_SYS_I2C_EEPROM_ADDR, 0, buf, EEPROM_LEN);
Heiko Schocher566a4942007-06-22 19:11:54 +0200203 if (ret == 0) {
Wolfgang Denkd2567be2009-03-28 20:16:16 +0100204 checksumcrc16 = cyg_crc16 (buf, EEPROM_LEN - 2);
Heiko Schocher566a4942007-06-22 19:11:54 +0200205 /* check, if the EEprom is programmed:
206 * - The Prefix(Byte 0,1,2) is equal to "ATR"
207 * - The checksum, stored in the last 2 Bytes, is correct
208 */
Wolfgang Denkd2567be2009-03-28 20:16:16 +0100209 if ((strncmp ((char *)buf,"ATR",3) != 0) ||
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200210 ((checksumcrc16 >> 8) != buf[EEPROM_LEN - 2]) ||
211 ((checksumcrc16 & 0xff) != buf[EEPROM_LEN - 1])) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200212 /* EEprom is not programmed */
213 printf("%s: EEPROM Checksum not OK\n", __FUNCTION__);
214 } else {
215 /* get the MACs */
Mike Frysinger9c150102009-02-11 20:09:52 -0500216 if (!ok_ethaddr)
217 eth_setenv_enetaddr("ethaddr", &buf[3]);
218 if (!ok_eth1addr)
219 eth_setenv_enetaddr("eth1addr", &buf[9]);
Heiko Schocher566a4942007-06-22 19:11:54 +0200220 return;
221 }
222 }
223
224 /* some error reading the EEprom */
225 if ((use_eeprom = getenv ("use_eeprom_ethaddr")) == NULL) {
226 /* dont use bootcmd */
227 setenv("bootdelay", "-1");
228 return;
229 }
230 /* == default ? use standard */
231 if (strncmp (use_eeprom, "default", 7) == 0) {
232 return;
233 }
234 /* Env doesnt exist -> hang */
235 status_led_blink ();
Heiko Schocher90790242007-07-13 08:26:05 +0200236 /* here we do this "handy" because we have no interrupts
237 at this time */
238 puts ("### EEPROM ERROR ### Please RESET the board ###\n");
239 for (;;) {
240 __led_toggle (12);
241 udelay (100000);
242 }
Heiko Schocher566a4942007-06-22 19:11:54 +0200243 return;
244}
245
246#ifdef CONFIG_PREBOOT
247
248static uchar kbd_magic_prefix[] = "key_magic";
249static uchar kbd_command_prefix[] = "key_cmd";
250
251struct kbd_data_t {
252 char s1;
253 char s2;
254};
255
256struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
257{
258 char *val;
259 unsigned long tmp;
260
261 /* use the DIPs for some bootoptions */
262 val = getenv (ENV_NAME_DIP);
263 tmp = simple_strtoul (val, NULL, 16);
264
265 kbd_data->s2 = (tmp & 0x0f);
266 kbd_data->s1 = (tmp & 0xf0) >> 4;
267 return kbd_data;
268}
269
270static int compare_magic (const struct kbd_data_t *kbd_data, char *str)
271{
272 char s1 = str[0];
273
274 if (s1 >= '0' && s1 <= '9')
275 s1 -= '0';
276 else if (s1 >= 'a' && s1 <= 'f')
277 s1 = s1 - 'a' + 10;
278 else if (s1 >= 'A' && s1 <= 'F')
279 s1 = s1 - 'A' + 10;
280 else
281 return -1;
282
283 if (s1 != kbd_data->s1) return -1;
284
285 s1 = str[1];
286 if (s1 >= '0' && s1 <= '9')
287 s1 -= '0';
288 else if (s1 >= 'a' && s1 <= 'f')
289 s1 = s1 - 'a' + 10;
290 else if (s1 >= 'A' && s1 <= 'F')
291 s1 = s1 - 'A' + 10;
292 else
293 return -1;
294
295 if (s1 != kbd_data->s2) return -1;
296 return 0;
297}
298
299static char *key_match (const struct kbd_data_t *kbd_data)
300{
301 char magic[sizeof (kbd_magic_prefix) + 1];
302 char *suffix;
303 char *kbd_magic_keys;
304
305 /*
306 * The following string defines the characters that can be appended
307 * to "key_magic" to form the names of environment variables that
308 * hold "magic" key codes, i. e. such key codes that can cause
309 * pre-boot actions. If the string is empty (""), then only
310 * "key_magic" is checked (old behaviour); the string "125" causes
311 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
312 */
313 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
314 kbd_magic_keys = "";
315
316 /* loop over all magic keys;
317 * use '\0' suffix in case of empty string
318 */
319 for (suffix = kbd_magic_keys; *suffix ||
320 suffix == kbd_magic_keys; ++suffix) {
321 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
322 if (compare_magic (kbd_data, getenv (magic)) == 0) {
323 char cmd_name[sizeof (kbd_command_prefix) + 1];
324 char *cmd;
325
326 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
327 cmd = getenv (cmd_name);
328
329 return (cmd);
330 }
331 }
332 return (NULL);
333}
334
335#endif /* CONFIG_PREBOOT */
336
337static int pcs440ep_readinputs (void)
338{
339 int i;
340 char value[20];
341
342 /* read the inputs and set the Envvars */
343 /* Revision Level Bit 26 - 29 */
344 i = ((in32 (GPIO0_IR) & 0x0000003c) >> 2);
345 i = swapbits[i];
346 sprintf (value, "%02x", i);
347 setenv (ENV_NAME_REVLEV, value);
348 /* Solder Switch Bit 30 - 33 */
349 i = (in32 (GPIO0_IR) & 0x00000003) << 2;
350 i += (in32 (GPIO1_IR) & 0xc0000000) >> 30;
351 i = swapbits[i];
352 sprintf (value, "%02x", i);
353 setenv (ENV_NAME_SOLDER, value);
354 /* DIP Switch Bit 49 - 56 */
355 i = ((in32 (GPIO1_IR) & 0x00007f80) >> 7);
356 i = (swapbits[i & 0x0f] << 4) + swapbits[(i & 0xf0) >> 4];
357 sprintf (value, "%02x", i);
358 setenv (ENV_NAME_DIP, value);
359 return 0;
360}
361
362
363#if defined(CONFIG_SHA1_CHECK_UB_IMG)
364/*************************************************************************
365 * calculate a SHA1 sum for the U-Boot image in Flash.
366 *
367 ************************************************************************/
368static int pcs440ep_sha1 (int docheck)
369{
370 unsigned char *data;
371 unsigned char *ptroff;
372 unsigned char output[20];
373 unsigned char org[20];
374 int i, len = CONFIG_SHA1_LEN;
375
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200376 memcpy ((char *)CONFIG_SYS_LOAD_ADDR, (char *)CONFIG_SHA1_START, len);
377 data = (unsigned char *)CONFIG_SYS_LOAD_ADDR;
Heiko Schocher566a4942007-06-22 19:11:54 +0200378 ptroff = &data[len + SHA1_SUM_POS];
379
380 for (i = 0; i < SHA1_SUM_LEN; i++) {
381 org[i] = ptroff[i];
382 ptroff[i] = 0;
383 }
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200384
Heiko Schocher566a4942007-06-22 19:11:54 +0200385 sha1_csum ((unsigned char *) data, len, (unsigned char *)output);
386
387 if (docheck == 2) {
388 for (i = 0; i < 20 ; i++) {
389 printf("%02X ", output[i]);
390 }
391 printf("\n");
392 }
393 if (docheck == 1) {
394 for (i = 0; i < 20 ; i++) {
395 if (org[i] != output[i]) return 1;
396 }
397 }
398 return 0;
399}
400
401/*************************************************************************
402 * do some checks after the SHA1 checksum from the U-Boot Image was
403 * calculated.
404 *
405 ************************************************************************/
406static void pcs440ep_checksha1 (void)
407{
408 int ret;
409 char *cs_test;
410
Heiko Schocher96e1d752007-07-11 18:39:11 +0200411 status_led_set (0, STATUS_LED_OFF);
412 status_led_set (1, STATUS_LED_OFF);
413 status_led_set (2, STATUS_LED_ON);
Heiko Schocher566a4942007-06-22 19:11:54 +0200414 ret = pcs440ep_sha1 (1);
415 if (ret == 0) return;
416
417 if ((cs_test = getenv ("cs_test")) == NULL) {
418 /* Env doesnt exist -> hang */
419 status_led_blink ();
Heiko Schocher90790242007-07-13 08:26:05 +0200420 /* here we do this "handy" because we have no interrupts
421 at this time */
422 puts ("### SHA1 ERROR ### Please RESET the board ###\n");
423 for (;;) {
424 __led_toggle (2);
425 udelay (100000);
426 }
Heiko Schocher566a4942007-06-22 19:11:54 +0200427 }
428
429 if (strncmp (cs_test, "off", 3) == 0) {
430 printf ("SHA1 U-Boot sum NOT ok!\n");
431 setenv ("bootdelay", "-1");
432 }
433}
434#else
435static __inline__ void pcs440ep_checksha1 (void) { do {} while (0);}
436#endif
437
Stefan Roesea4c8d132006-06-02 16:18:04 +0200438int misc_init_r (void)
439{
440 uint pbcr;
441 int size_val = 0;
442
Mike Frysinger9c150102009-02-11 20:09:52 -0500443 load_ethaddr();
444
Stefan Roesea4c8d132006-06-02 16:18:04 +0200445 /* Re-do sizing to get full correct info */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200446 mtdcr(EBC0_CFGADDR, PB0CR);
447 pbcr = mfdcr(EBC0_CFGDATA);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200448 switch (gd->bd->bi_flashsize) {
449 case 1 << 20:
450 size_val = 0;
451 break;
452 case 2 << 20:
453 size_val = 1;
454 break;
455 case 4 << 20:
456 size_val = 2;
457 break;
458 case 8 << 20:
459 size_val = 3;
460 break;
461 case 16 << 20:
462 size_val = 4;
463 break;
464 case 32 << 20:
465 size_val = 5;
466 break;
467 case 64 << 20:
468 size_val = 6;
469 break;
470 case 128 << 20:
471 size_val = 7;
472 break;
473 }
474 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
Stefan Roesed1c3b272009-09-09 16:25:29 +0200475 mtdcr(EBC0_CFGADDR, PB0CR);
476 mtdcr(EBC0_CFGDATA, pbcr);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200477
478 /* adjust flash start and offset */
479 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
480 gd->bd->bi_flashoffset = 0;
481
482 /* Monitor protection ON by default */
483 (void)flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200484 -CONFIG_SYS_MONITOR_LEN,
Stefan Roesea4c8d132006-06-02 16:18:04 +0200485 0xffffffff,
486 &flash_info[1]);
487
488 /* Env protection ON by default */
489 (void)flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200490 CONFIG_ENV_ADDR_REDUND,
491 CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese4526c872006-06-06 10:59:12 +0200492 &flash_info[1]);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200493
Heiko Schocher566a4942007-06-22 19:11:54 +0200494 pcs440ep_readinputs ();
495 pcs440ep_checksha1 ();
496#ifdef CONFIG_PREBOOT
497 {
498 struct kbd_data_t kbd_data;
499 /* Decode keys */
500 char *str = strdup (key_match (get_keys (&kbd_data)));
501 /* Set or delete definition */
502 setenv ("preboot", str);
503 free (str);
504 }
505#endif /* CONFIG_PREBOOT */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200506 return 0;
507}
508
509int checkboard(void)
510{
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000511 char buf[64];
512 int i = getenv_f("serial#", buf, sizeof(buf));
Stefan Roesea4c8d132006-06-02 16:18:04 +0200513
514 printf("Board: PCS440EP");
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000515 if (i > 0) {
Stefan Roesea4c8d132006-06-02 16:18:04 +0200516 puts(", serial# ");
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000517 puts(buf);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200518 }
519 putc('\n');
520
521 return (0);
522}
523
Heiko Schocher566a4942007-06-22 19:11:54 +0200524void spd_ddr_init_hang (void)
525{
526 status_led_set (0, STATUS_LED_OFF);
527 status_led_set (1, STATUS_LED_ON);
528 /* we cannot use hang() because we are still running from
529 Flash, and so the status_led driver is not initialized */
Heiko Schocher90790242007-07-13 08:26:05 +0200530 puts ("### SDRAM ERROR ### Please RESET the board ###\n");
Heiko Schocher566a4942007-06-22 19:11:54 +0200531 for (;;) {
532 __led_toggle (4);
533 udelay (100000);
534 }
535}
Heiko Schocher566a4942007-06-22 19:11:54 +0200536
Becky Bruce9973e3c2008-06-09 16:03:40 -0500537phys_size_t initdram (int board_type)
Stefan Roesea4c8d132006-06-02 16:18:04 +0200538{
539 long dram_size = 0;
540
Heiko Schocher566a4942007-06-22 19:11:54 +0200541 status_led_set (0, STATUS_LED_ON);
542 status_led_set (1, STATUS_LED_OFF);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200543 dram_size = spd_sdram();
Heiko Schocher566a4942007-06-22 19:11:54 +0200544 status_led_set (0, STATUS_LED_OFF);
545 status_led_set (1, STATUS_LED_ON);
546 if (dram_size == 0) {
547 hang();
548 }
Stefan Roesea4c8d132006-06-02 16:18:04 +0200549
550 return dram_size;
551}
552
Stefan Roesea4c8d132006-06-02 16:18:04 +0200553/*************************************************************************
Stefan Roesea4c8d132006-06-02 16:18:04 +0200554 * hw_watchdog_reset
555 *
556 * This routine is called to reset (keep alive) the watchdog timer
557 *
558 ************************************************************************/
559#if defined(CONFIG_HW_WATCHDOG)
560void hw_watchdog_reset(void)
561{
562
563}
564#endif
Heiko Schocher566a4942007-06-22 19:11:54 +0200565
566/*************************************************************************
567 * "led" Commando for the U-Boot shell
568 *
569 ************************************************************************/
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200570int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Heiko Schocher566a4942007-06-22 19:11:54 +0200571{
Heiko Schocher96e1d752007-07-11 18:39:11 +0200572 int rcode = 0, i;
Heiko Schocher566a4942007-06-22 19:11:54 +0200573 ulong pattern = 0;
574
Heiko Schocher96e1d752007-07-11 18:39:11 +0200575 pattern = simple_strtoul (argv[1], NULL, 16);
576 if (pattern > 0x400) {
577 int val = GET_LEDS;
578 printf ("led: %x\n", val);
579 return rcode;
580 }
581 if (pattern > 0x200) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200582 status_led_blink ();
583 hang ();
584 return rcode;
585 }
Heiko Schocher96e1d752007-07-11 18:39:11 +0200586 if (pattern > 0x100) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200587 status_led_blink ();
588 return rcode;
589 }
590 pattern &= 0x0f;
Heiko Schocher96e1d752007-07-11 18:39:11 +0200591 for (i = 0; i < 4; i++) {
592 if (pattern & 0x01) status_led_set (i, STATUS_LED_ON);
593 else status_led_set (i, STATUS_LED_OFF);
594 pattern = pattern >> 1;
595 }
Heiko Schocher566a4942007-06-22 19:11:54 +0200596 return rcode;
597}
598
599U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200600 led, 2, 1, do_led,
Peter Tyser2fb26042009-01-27 18:03:12 -0600601 "set the DIAG-LED",
Heiko Schocher96e1d752007-07-11 18:39:11 +0200602 "[bitmask] 0x01 = DIAG 1 on\n"
603 " 0x02 = DIAG 2 on\n"
604 " 0x04 = DIAG 3 on\n"
605 " 0x08 = DIAG 4 on\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200606 " > 0x100 set the LED, who are on, to state blinking"
Heiko Schocher566a4942007-06-22 19:11:54 +0200607);
608
609#if defined(CONFIG_SHA1_CHECK_UB_IMG)
610/*************************************************************************
611 * "sha1" Commando for the U-Boot shell
612 *
613 ************************************************************************/
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200614int do_sha1 (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Heiko Schocher566a4942007-06-22 19:11:54 +0200615{
616 int rcode = -1;
617
618 if (argc < 2) {
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200619usage:
620 return cmd_usage(cmdtp);
Heiko Schocher566a4942007-06-22 19:11:54 +0200621 }
622
623 if (argc >= 3) {
624 unsigned char *data;
625 unsigned char output[20];
626 int len;
627 int i;
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200628
Heiko Schocher566a4942007-06-22 19:11:54 +0200629 data = (unsigned char *)simple_strtoul (argv[1], NULL, 16);
630 len = simple_strtoul (argv[2], NULL, 16);
631 sha1_csum (data, len, (unsigned char *)output);
632 printf ("U-Boot sum:\n");
633 for (i = 0; i < 20 ; i++) {
634 printf ("%02X ", output[i]);
635 }
636 printf ("\n");
637 if (argc == 4) {
638 data = (unsigned char *)simple_strtoul (argv[3], NULL, 16);
639 memcpy (data, output, 20);
640 }
641 return 0;
642 }
643 if (argc == 2) {
644 char *ptr = argv[1];
645 if (*ptr != '-') goto usage;
646 ptr++;
647 if ((*ptr == 'c') || (*ptr == 'C')) {
648 rcode = pcs440ep_sha1 (1);
649 printf ("SHA1 U-Boot sum %sok!\n", (rcode != 0) ? "not " : "");
650 } else if ((*ptr == 'p') || (*ptr == 'P')) {
651 rcode = pcs440ep_sha1 (2);
652 } else {
653 rcode = pcs440ep_sha1 (0);
654 }
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200655 return rcode;
Heiko Schocher566a4942007-06-22 19:11:54 +0200656 }
657 return rcode;
658}
659
660U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200661 sha1, 4, 1, do_sha1,
Peter Tyser2fb26042009-01-27 18:03:12 -0600662 "calculate the SHA1 Sum",
Heiko Schocher566a4942007-06-22 19:11:54 +0200663 "address len [addr] calculate the SHA1 sum [save at addr]\n"
664 " -p calculate the SHA1 sum from the U-Boot image in flash and print\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200665 " -c check the U-Boot image in flash"
Heiko Schocher566a4942007-06-22 19:11:54 +0200666);
667#endif
668
Heiko Schocherf98984c2007-08-28 17:39:14 +0200669#if defined (CONFIG_CMD_IDE)
670/* These addresses need to be shifted one place to the left
671 * ( bus per_addr 20 -30 is connectsd on CF bus A10-A0)
672 * These values are shifted
673 */
674extern ulong *ide_bus_offset;
675void inline ide_outb(int dev, int port, unsigned char val)
676{
677 debug ("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
678 dev, port, val, (ATA_CURR_BASE(dev)+port));
679
680 out_be16((u16 *)(ATA_CURR_BASE(dev)+(port << 1)), val);
681}
682unsigned char inline ide_inb(int dev, int port)
683{
684 uchar val;
685 val = in_be16((u16 *)(ATA_CURR_BASE(dev)+(port << 1)));
686 debug ("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
687 dev, port, (ATA_CURR_BASE(dev)+port), val);
688 return (val);
689}
690#endif
691
Heiko Schocher566a4942007-06-22 19:11:54 +0200692#ifdef CONFIG_IDE_PREINIT
693int ide_preinit (void)
694{
695 /* Set True IDE Mode */
696 out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00100000));
697 out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
698 out32 (GPIO1_OR, (in32 (GPIO1_OR) & ~0x00008040));
699 udelay (100000);
700 return 0;
701}
702#endif
703
Wolfgang Denkafaac862007-08-12 14:27:39 +0200704#if defined (CONFIG_CMD_IDE) && defined (CONFIG_IDE_RESET)
Heiko Schocher566a4942007-06-22 19:11:54 +0200705void ide_set_reset (int idereset)
706{
707 debug ("ide_reset(%d)\n", idereset);
708 if (idereset == 0) {
709 out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
710 } else {
711 out32 (GPIO0_OR, (in32 (GPIO0_OR) & ~0x00200000));
712 }
713 udelay (10000);
714}
Wolfgang Denkafaac862007-08-12 14:27:39 +0200715#endif /* defined (CONFIG_CMD_IDE) && defined (CONFIG_IDE_RESET) */