blob: 746a54c5e3405d8007529f401d15e943fb1a6c59 [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 */
Simon Glass8ade9502011-12-10 11:07:58 +0000100 if (val == -BOOTSTAGE_ID_NEED_RESET)
101 return;
Heiko Schocher566a4942007-06-22 19:11:54 +0200102 if (val < 0) {
103 /* smthing goes wrong */
104 status_led_blink ();
105 return;
106 }
107 switch (val) {
Simon Glass5dc88712012-01-14 15:24:47 +0000108 case BOOTSTAGE_ID_CHECK_MAGIC:
109 /* validating Image */
110 status_led_set(0, STATUS_LED_OFF);
111 status_led_set(1, STATUS_LED_ON);
112 status_led_set(2, STATUS_LED_ON);
113 break;
114 case BOOTSTAGE_ID_RUN_OS:
115 status_led_set(0, STATUS_LED_ON);
116 status_led_set(1, STATUS_LED_ON);
117 status_led_set(2, STATUS_LED_ON);
118 break;
Heiko Schocher96e1d752007-07-11 18:39:11 +0200119#if 0
Simon Glassc8e66db2012-01-14 15:24:52 +0000120 case BOOTSTAGE_ID_NET_ETH_START:
121 /* starting Ethernet configuration */
122 status_led_set(0, STATUS_LED_OFF);
123 status_led_set(1, STATUS_LED_OFF);
124 status_led_set(2, STATUS_LED_ON);
125 break;
Heiko Schocher96e1d752007-07-11 18:39:11 +0200126#endif
Simon Glassc8e66db2012-01-14 15:24:52 +0000127 case BOOTSTAGE_ID_NET_START:
128 /* loading Image */
129 status_led_set(0, STATUS_LED_ON);
130 status_led_set(1, STATUS_LED_OFF);
131 status_led_set(2, STATUS_LED_ON);
132 break;
Heiko Schocher566a4942007-06-22 19:11:54 +0200133 }
134}
135#endif
136
Stefan Roesea4c8d132006-06-02 16:18:04 +0200137int board_early_init_f(void)
138{
139 register uint reg;
140
141 set_leds(0); /* display boot info counter */
142
143 /*--------------------------------------------------------------------
144 * Setup the external bus controller/chip selects
145 *-------------------------------------------------------------------*/
Stefan Roesed1c3b272009-09-09 16:25:29 +0200146 mtdcr(EBC0_CFGADDR, EBC0_CFG);
147 reg = mfdcr(EBC0_CFGDATA);
148 mtdcr(EBC0_CFGDATA, reg | 0x04000000); /* Set ATC */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200149
150 /*--------------------------------------------------------------------
Stefan Roesea47a12b2010-04-15 16:07:28 +0200151 * GPIO's are alreay setup in arch/powerpc/cpu/ppc4xx/cpu_init.c
Stefan Roesea4c8d132006-06-02 16:18:04 +0200152 * via define from board config file.
153 *-------------------------------------------------------------------*/
154
155 /*--------------------------------------------------------------------
156 * Setup the interrupt controller polarities, triggers, etc.
157 *-------------------------------------------------------------------*/
Stefan Roese952e7762009-09-24 09:55:50 +0200158 mtdcr(UIC0SR, 0xffffffff); /* clear all */
159 mtdcr(UIC0ER, 0x00000000); /* disable all */
160 mtdcr(UIC0CR, 0x00000001); /* UIC1 crit is critical */
161 mtdcr(UIC0PR, 0xfffffe1f); /* per ref-board manual */
162 mtdcr(UIC0TR, 0x01c00000); /* per ref-board manual */
163 mtdcr(UIC0VR, 0x00000001); /* int31 highest, base=0x000 */
164 mtdcr(UIC0SR, 0xffffffff); /* clear all */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200165
Stefan Roese952e7762009-09-24 09:55:50 +0200166 mtdcr(UIC1SR, 0xffffffff); /* clear all */
167 mtdcr(UIC1ER, 0x00000000); /* disable all */
168 mtdcr(UIC1CR, 0x00000000); /* all non-critical */
169 mtdcr(UIC1PR, 0xffffe0ff); /* per ref-board manual */
170 mtdcr(UIC1TR, 0x00ffc000); /* per ref-board manual */
171 mtdcr(UIC1VR, 0x00000001); /* int31 highest, base=0x000 */
172 mtdcr(UIC1SR, 0xffffffff); /* clear all */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200173
174 /*--------------------------------------------------------------------
175 * Setup other serial configuration
176 *-------------------------------------------------------------------*/
Stefan Roesed1c3b272009-09-09 16:25:29 +0200177 mfsdr(SDR0_PCI0, reg);
178 mtsdr(SDR0_PCI0, 0x80000000 | reg); /* PCI arbiter enabled */
179 mtsdr(SDR0_PFC0, 0x00000000); /* Pin function: enable GPIO49-63 */
180 mtsdr(SDR0_PFC1, 0x00048000); /* Pin function: UART0 has 4 pins, select IRQ5 */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200181
182 return 0;
183}
184
Heiko Schocher566a4942007-06-22 19:11:54 +0200185#define EEPROM_LEN 256
Mike Frysinger9c150102009-02-11 20:09:52 -0500186static void load_ethaddr(void)
Heiko Schocher566a4942007-06-22 19:11:54 +0200187{
Mike Frysinger9c150102009-02-11 20:09:52 -0500188 int ok_ethaddr, ok_eth1addr;
Heiko Schocher566a4942007-06-22 19:11:54 +0200189 int ret;
Wolfgang Denkd2567be2009-03-28 20:16:16 +0100190 uchar buf[EEPROM_LEN];
Heiko Schocher566a4942007-06-22 19:11:54 +0200191 char *use_eeprom;
192 u16 checksumcrc16 = 0;
193
Mike Frysinger9c150102009-02-11 20:09:52 -0500194 /* If the env is sane, then nothing for us to do */
195 ok_ethaddr = eth_getenv_enetaddr("ethaddr", buf);
196 ok_eth1addr = eth_getenv_enetaddr("eth1addr", buf);
197 if (ok_ethaddr && ok_eth1addr)
198 return;
199
Heiko Schocher566a4942007-06-22 19:11:54 +0200200 /* read the MACs from EEprom */
201 status_led_set (0, STATUS_LED_ON);
202 status_led_set (1, STATUS_LED_ON);
Wolfgang Denkd2567be2009-03-28 20:16:16 +0100203 ret = eeprom_read (CONFIG_SYS_I2C_EEPROM_ADDR, 0, buf, EEPROM_LEN);
Heiko Schocher566a4942007-06-22 19:11:54 +0200204 if (ret == 0) {
Wolfgang Denkd2567be2009-03-28 20:16:16 +0100205 checksumcrc16 = cyg_crc16 (buf, EEPROM_LEN - 2);
Heiko Schocher566a4942007-06-22 19:11:54 +0200206 /* check, if the EEprom is programmed:
207 * - The Prefix(Byte 0,1,2) is equal to "ATR"
208 * - The checksum, stored in the last 2 Bytes, is correct
209 */
Wolfgang Denkd2567be2009-03-28 20:16:16 +0100210 if ((strncmp ((char *)buf,"ATR",3) != 0) ||
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200211 ((checksumcrc16 >> 8) != buf[EEPROM_LEN - 2]) ||
212 ((checksumcrc16 & 0xff) != buf[EEPROM_LEN - 1])) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200213 /* EEprom is not programmed */
214 printf("%s: EEPROM Checksum not OK\n", __FUNCTION__);
215 } else {
216 /* get the MACs */
Mike Frysinger9c150102009-02-11 20:09:52 -0500217 if (!ok_ethaddr)
218 eth_setenv_enetaddr("ethaddr", &buf[3]);
219 if (!ok_eth1addr)
220 eth_setenv_enetaddr("eth1addr", &buf[9]);
Heiko Schocher566a4942007-06-22 19:11:54 +0200221 return;
222 }
223 }
224
225 /* some error reading the EEprom */
226 if ((use_eeprom = getenv ("use_eeprom_ethaddr")) == NULL) {
227 /* dont use bootcmd */
228 setenv("bootdelay", "-1");
229 return;
230 }
231 /* == default ? use standard */
232 if (strncmp (use_eeprom, "default", 7) == 0) {
233 return;
234 }
235 /* Env doesnt exist -> hang */
236 status_led_blink ();
Heiko Schocher90790242007-07-13 08:26:05 +0200237 /* here we do this "handy" because we have no interrupts
238 at this time */
239 puts ("### EEPROM ERROR ### Please RESET the board ###\n");
240 for (;;) {
241 __led_toggle (12);
242 udelay (100000);
243 }
Heiko Schocher566a4942007-06-22 19:11:54 +0200244 return;
245}
246
247#ifdef CONFIG_PREBOOT
248
249static uchar kbd_magic_prefix[] = "key_magic";
250static uchar kbd_command_prefix[] = "key_cmd";
251
252struct kbd_data_t {
253 char s1;
254 char s2;
255};
256
257struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
258{
259 char *val;
260 unsigned long tmp;
261
262 /* use the DIPs for some bootoptions */
263 val = getenv (ENV_NAME_DIP);
264 tmp = simple_strtoul (val, NULL, 16);
265
266 kbd_data->s2 = (tmp & 0x0f);
267 kbd_data->s1 = (tmp & 0xf0) >> 4;
268 return kbd_data;
269}
270
271static int compare_magic (const struct kbd_data_t *kbd_data, char *str)
272{
273 char s1 = str[0];
274
275 if (s1 >= '0' && s1 <= '9')
276 s1 -= '0';
277 else if (s1 >= 'a' && s1 <= 'f')
278 s1 = s1 - 'a' + 10;
279 else if (s1 >= 'A' && s1 <= 'F')
280 s1 = s1 - 'A' + 10;
281 else
282 return -1;
283
284 if (s1 != kbd_data->s1) return -1;
285
286 s1 = str[1];
287 if (s1 >= '0' && s1 <= '9')
288 s1 -= '0';
289 else if (s1 >= 'a' && s1 <= 'f')
290 s1 = s1 - 'a' + 10;
291 else if (s1 >= 'A' && s1 <= 'F')
292 s1 = s1 - 'A' + 10;
293 else
294 return -1;
295
296 if (s1 != kbd_data->s2) return -1;
297 return 0;
298}
299
300static char *key_match (const struct kbd_data_t *kbd_data)
301{
302 char magic[sizeof (kbd_magic_prefix) + 1];
303 char *suffix;
304 char *kbd_magic_keys;
305
306 /*
307 * The following string defines the characters that can be appended
308 * to "key_magic" to form the names of environment variables that
309 * hold "magic" key codes, i. e. such key codes that can cause
310 * pre-boot actions. If the string is empty (""), then only
311 * "key_magic" is checked (old behaviour); the string "125" causes
312 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
313 */
314 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
315 kbd_magic_keys = "";
316
317 /* loop over all magic keys;
318 * use '\0' suffix in case of empty string
319 */
320 for (suffix = kbd_magic_keys; *suffix ||
321 suffix == kbd_magic_keys; ++suffix) {
322 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
323 if (compare_magic (kbd_data, getenv (magic)) == 0) {
324 char cmd_name[sizeof (kbd_command_prefix) + 1];
325 char *cmd;
326
327 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
328 cmd = getenv (cmd_name);
329
330 return (cmd);
331 }
332 }
333 return (NULL);
334}
335
336#endif /* CONFIG_PREBOOT */
337
338static int pcs440ep_readinputs (void)
339{
340 int i;
341 char value[20];
342
343 /* read the inputs and set the Envvars */
344 /* Revision Level Bit 26 - 29 */
345 i = ((in32 (GPIO0_IR) & 0x0000003c) >> 2);
346 i = swapbits[i];
347 sprintf (value, "%02x", i);
348 setenv (ENV_NAME_REVLEV, value);
349 /* Solder Switch Bit 30 - 33 */
350 i = (in32 (GPIO0_IR) & 0x00000003) << 2;
351 i += (in32 (GPIO1_IR) & 0xc0000000) >> 30;
352 i = swapbits[i];
353 sprintf (value, "%02x", i);
354 setenv (ENV_NAME_SOLDER, value);
355 /* DIP Switch Bit 49 - 56 */
356 i = ((in32 (GPIO1_IR) & 0x00007f80) >> 7);
357 i = (swapbits[i & 0x0f] << 4) + swapbits[(i & 0xf0) >> 4];
358 sprintf (value, "%02x", i);
359 setenv (ENV_NAME_DIP, value);
360 return 0;
361}
362
363
364#if defined(CONFIG_SHA1_CHECK_UB_IMG)
365/*************************************************************************
366 * calculate a SHA1 sum for the U-Boot image in Flash.
367 *
368 ************************************************************************/
369static int pcs440ep_sha1 (int docheck)
370{
371 unsigned char *data;
372 unsigned char *ptroff;
373 unsigned char output[20];
374 unsigned char org[20];
375 int i, len = CONFIG_SHA1_LEN;
376
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200377 memcpy ((char *)CONFIG_SYS_LOAD_ADDR, (char *)CONFIG_SHA1_START, len);
378 data = (unsigned char *)CONFIG_SYS_LOAD_ADDR;
Heiko Schocher566a4942007-06-22 19:11:54 +0200379 ptroff = &data[len + SHA1_SUM_POS];
380
381 for (i = 0; i < SHA1_SUM_LEN; i++) {
382 org[i] = ptroff[i];
383 ptroff[i] = 0;
384 }
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200385
Heiko Schocher566a4942007-06-22 19:11:54 +0200386 sha1_csum ((unsigned char *) data, len, (unsigned char *)output);
387
388 if (docheck == 2) {
389 for (i = 0; i < 20 ; i++) {
390 printf("%02X ", output[i]);
391 }
392 printf("\n");
393 }
394 if (docheck == 1) {
395 for (i = 0; i < 20 ; i++) {
396 if (org[i] != output[i]) return 1;
397 }
398 }
399 return 0;
400}
401
402/*************************************************************************
403 * do some checks after the SHA1 checksum from the U-Boot Image was
404 * calculated.
405 *
406 ************************************************************************/
407static void pcs440ep_checksha1 (void)
408{
409 int ret;
410 char *cs_test;
411
Heiko Schocher96e1d752007-07-11 18:39:11 +0200412 status_led_set (0, STATUS_LED_OFF);
413 status_led_set (1, STATUS_LED_OFF);
414 status_led_set (2, STATUS_LED_ON);
Heiko Schocher566a4942007-06-22 19:11:54 +0200415 ret = pcs440ep_sha1 (1);
416 if (ret == 0) return;
417
418 if ((cs_test = getenv ("cs_test")) == NULL) {
419 /* Env doesnt exist -> hang */
420 status_led_blink ();
Heiko Schocher90790242007-07-13 08:26:05 +0200421 /* here we do this "handy" because we have no interrupts
422 at this time */
423 puts ("### SHA1 ERROR ### Please RESET the board ###\n");
424 for (;;) {
425 __led_toggle (2);
426 udelay (100000);
427 }
Heiko Schocher566a4942007-06-22 19:11:54 +0200428 }
429
430 if (strncmp (cs_test, "off", 3) == 0) {
431 printf ("SHA1 U-Boot sum NOT ok!\n");
432 setenv ("bootdelay", "-1");
433 }
434}
435#else
436static __inline__ void pcs440ep_checksha1 (void) { do {} while (0);}
437#endif
438
Stefan Roesea4c8d132006-06-02 16:18:04 +0200439int misc_init_r (void)
440{
441 uint pbcr;
442 int size_val = 0;
443
Mike Frysinger9c150102009-02-11 20:09:52 -0500444 load_ethaddr();
445
Stefan Roesea4c8d132006-06-02 16:18:04 +0200446 /* Re-do sizing to get full correct info */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200447 mtdcr(EBC0_CFGADDR, PB0CR);
448 pbcr = mfdcr(EBC0_CFGDATA);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200449 switch (gd->bd->bi_flashsize) {
450 case 1 << 20:
451 size_val = 0;
452 break;
453 case 2 << 20:
454 size_val = 1;
455 break;
456 case 4 << 20:
457 size_val = 2;
458 break;
459 case 8 << 20:
460 size_val = 3;
461 break;
462 case 16 << 20:
463 size_val = 4;
464 break;
465 case 32 << 20:
466 size_val = 5;
467 break;
468 case 64 << 20:
469 size_val = 6;
470 break;
471 case 128 << 20:
472 size_val = 7;
473 break;
474 }
475 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
Stefan Roesed1c3b272009-09-09 16:25:29 +0200476 mtdcr(EBC0_CFGADDR, PB0CR);
477 mtdcr(EBC0_CFGDATA, pbcr);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200478
479 /* adjust flash start and offset */
480 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
481 gd->bd->bi_flashoffset = 0;
482
483 /* Monitor protection ON by default */
484 (void)flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200485 -CONFIG_SYS_MONITOR_LEN,
Stefan Roesea4c8d132006-06-02 16:18:04 +0200486 0xffffffff,
487 &flash_info[1]);
488
489 /* Env protection ON by default */
490 (void)flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200491 CONFIG_ENV_ADDR_REDUND,
492 CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese4526c872006-06-06 10:59:12 +0200493 &flash_info[1]);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200494
Heiko Schocher566a4942007-06-22 19:11:54 +0200495 pcs440ep_readinputs ();
496 pcs440ep_checksha1 ();
497#ifdef CONFIG_PREBOOT
498 {
499 struct kbd_data_t kbd_data;
500 /* Decode keys */
501 char *str = strdup (key_match (get_keys (&kbd_data)));
502 /* Set or delete definition */
503 setenv ("preboot", str);
504 free (str);
505 }
506#endif /* CONFIG_PREBOOT */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200507 return 0;
508}
509
510int checkboard(void)
511{
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000512 char buf[64];
513 int i = getenv_f("serial#", buf, sizeof(buf));
Stefan Roesea4c8d132006-06-02 16:18:04 +0200514
515 printf("Board: PCS440EP");
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000516 if (i > 0) {
Stefan Roesea4c8d132006-06-02 16:18:04 +0200517 puts(", serial# ");
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000518 puts(buf);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200519 }
520 putc('\n');
521
522 return (0);
523}
524
Heiko Schocher566a4942007-06-22 19:11:54 +0200525void spd_ddr_init_hang (void)
526{
527 status_led_set (0, STATUS_LED_OFF);
528 status_led_set (1, STATUS_LED_ON);
529 /* we cannot use hang() because we are still running from
530 Flash, and so the status_led driver is not initialized */
Heiko Schocher90790242007-07-13 08:26:05 +0200531 puts ("### SDRAM ERROR ### Please RESET the board ###\n");
Heiko Schocher566a4942007-06-22 19:11:54 +0200532 for (;;) {
533 __led_toggle (4);
534 udelay (100000);
535 }
536}
Heiko Schocher566a4942007-06-22 19:11:54 +0200537
Becky Bruce9973e3c2008-06-09 16:03:40 -0500538phys_size_t initdram (int board_type)
Stefan Roesea4c8d132006-06-02 16:18:04 +0200539{
540 long dram_size = 0;
541
Heiko Schocher566a4942007-06-22 19:11:54 +0200542 status_led_set (0, STATUS_LED_ON);
543 status_led_set (1, STATUS_LED_OFF);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200544 dram_size = spd_sdram();
Heiko Schocher566a4942007-06-22 19:11:54 +0200545 status_led_set (0, STATUS_LED_OFF);
546 status_led_set (1, STATUS_LED_ON);
547 if (dram_size == 0) {
548 hang();
549 }
Stefan Roesea4c8d132006-06-02 16:18:04 +0200550
551 return dram_size;
552}
553
Stefan Roesea4c8d132006-06-02 16:18:04 +0200554/*************************************************************************
Stefan Roesea4c8d132006-06-02 16:18:04 +0200555 * hw_watchdog_reset
556 *
557 * This routine is called to reset (keep alive) the watchdog timer
558 *
559 ************************************************************************/
560#if defined(CONFIG_HW_WATCHDOG)
561void hw_watchdog_reset(void)
562{
563
564}
565#endif
Heiko Schocher566a4942007-06-22 19:11:54 +0200566
567/*************************************************************************
568 * "led" Commando for the U-Boot shell
569 *
570 ************************************************************************/
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200571int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Heiko Schocher566a4942007-06-22 19:11:54 +0200572{
Heiko Schocher96e1d752007-07-11 18:39:11 +0200573 int rcode = 0, i;
Heiko Schocher566a4942007-06-22 19:11:54 +0200574 ulong pattern = 0;
575
Heiko Schocher96e1d752007-07-11 18:39:11 +0200576 pattern = simple_strtoul (argv[1], NULL, 16);
577 if (pattern > 0x400) {
578 int val = GET_LEDS;
579 printf ("led: %x\n", val);
580 return rcode;
581 }
582 if (pattern > 0x200) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200583 status_led_blink ();
584 hang ();
585 return rcode;
586 }
Heiko Schocher96e1d752007-07-11 18:39:11 +0200587 if (pattern > 0x100) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200588 status_led_blink ();
589 return rcode;
590 }
591 pattern &= 0x0f;
Heiko Schocher96e1d752007-07-11 18:39:11 +0200592 for (i = 0; i < 4; i++) {
593 if (pattern & 0x01) status_led_set (i, STATUS_LED_ON);
594 else status_led_set (i, STATUS_LED_OFF);
595 pattern = pattern >> 1;
596 }
Heiko Schocher566a4942007-06-22 19:11:54 +0200597 return rcode;
598}
599
600U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200601 led, 2, 1, do_led,
Peter Tyser2fb26042009-01-27 18:03:12 -0600602 "set the DIAG-LED",
Heiko Schocher96e1d752007-07-11 18:39:11 +0200603 "[bitmask] 0x01 = DIAG 1 on\n"
604 " 0x02 = DIAG 2 on\n"
605 " 0x04 = DIAG 3 on\n"
606 " 0x08 = DIAG 4 on\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200607 " > 0x100 set the LED, who are on, to state blinking"
Heiko Schocher566a4942007-06-22 19:11:54 +0200608);
609
610#if defined(CONFIG_SHA1_CHECK_UB_IMG)
611/*************************************************************************
612 * "sha1" Commando for the U-Boot shell
613 *
614 ************************************************************************/
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200615int do_sha1 (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Heiko Schocher566a4942007-06-22 19:11:54 +0200616{
617 int rcode = -1;
618
619 if (argc < 2) {
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200620usage:
621 return cmd_usage(cmdtp);
Heiko Schocher566a4942007-06-22 19:11:54 +0200622 }
623
624 if (argc >= 3) {
625 unsigned char *data;
626 unsigned char output[20];
627 int len;
628 int i;
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200629
Heiko Schocher566a4942007-06-22 19:11:54 +0200630 data = (unsigned char *)simple_strtoul (argv[1], NULL, 16);
631 len = simple_strtoul (argv[2], NULL, 16);
632 sha1_csum (data, len, (unsigned char *)output);
633 printf ("U-Boot sum:\n");
634 for (i = 0; i < 20 ; i++) {
635 printf ("%02X ", output[i]);
636 }
637 printf ("\n");
638 if (argc == 4) {
639 data = (unsigned char *)simple_strtoul (argv[3], NULL, 16);
640 memcpy (data, output, 20);
641 }
642 return 0;
643 }
644 if (argc == 2) {
645 char *ptr = argv[1];
646 if (*ptr != '-') goto usage;
647 ptr++;
648 if ((*ptr == 'c') || (*ptr == 'C')) {
649 rcode = pcs440ep_sha1 (1);
650 printf ("SHA1 U-Boot sum %sok!\n", (rcode != 0) ? "not " : "");
651 } else if ((*ptr == 'p') || (*ptr == 'P')) {
652 rcode = pcs440ep_sha1 (2);
653 } else {
654 rcode = pcs440ep_sha1 (0);
655 }
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200656 return rcode;
Heiko Schocher566a4942007-06-22 19:11:54 +0200657 }
658 return rcode;
659}
660
661U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200662 sha1, 4, 1, do_sha1,
Peter Tyser2fb26042009-01-27 18:03:12 -0600663 "calculate the SHA1 Sum",
Heiko Schocher566a4942007-06-22 19:11:54 +0200664 "address len [addr] calculate the SHA1 sum [save at addr]\n"
665 " -p calculate the SHA1 sum from the U-Boot image in flash and print\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200666 " -c check the U-Boot image in flash"
Heiko Schocher566a4942007-06-22 19:11:54 +0200667);
668#endif
669
Heiko Schocherf98984c2007-08-28 17:39:14 +0200670#if defined (CONFIG_CMD_IDE)
671/* These addresses need to be shifted one place to the left
672 * ( bus per_addr 20 -30 is connectsd on CF bus A10-A0)
673 * These values are shifted
674 */
675extern ulong *ide_bus_offset;
676void inline ide_outb(int dev, int port, unsigned char val)
677{
678 debug ("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
679 dev, port, val, (ATA_CURR_BASE(dev)+port));
680
681 out_be16((u16 *)(ATA_CURR_BASE(dev)+(port << 1)), val);
682}
683unsigned char inline ide_inb(int dev, int port)
684{
685 uchar val;
686 val = in_be16((u16 *)(ATA_CURR_BASE(dev)+(port << 1)));
687 debug ("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
688 dev, port, (ATA_CURR_BASE(dev)+port), val);
689 return (val);
690}
691#endif
692
Heiko Schocher566a4942007-06-22 19:11:54 +0200693#ifdef CONFIG_IDE_PREINIT
694int ide_preinit (void)
695{
696 /* Set True IDE Mode */
697 out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00100000));
698 out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
699 out32 (GPIO1_OR, (in32 (GPIO1_OR) & ~0x00008040));
700 udelay (100000);
701 return 0;
702}
703#endif
704
Wolfgang Denkafaac862007-08-12 14:27:39 +0200705#if defined (CONFIG_CMD_IDE) && defined (CONFIG_IDE_RESET)
Heiko Schocher566a4942007-06-22 19:11:54 +0200706void ide_set_reset (int idereset)
707{
708 debug ("ide_reset(%d)\n", idereset);
709 if (idereset == 0) {
710 out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
711 } else {
712 out32 (GPIO0_OR, (in32 (GPIO0_OR) & ~0x00200000));
713 }
714 udelay (10000);
715}
Wolfgang Denkafaac862007-08-12 14:27:39 +0200716#endif /* defined (CONFIG_CMD_IDE) && defined (CONFIG_IDE_RESET) */