blob: 0a934fb2cfb0e6d28b86bec50a84b885f52fb871 [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stefan Roesea4c8d132006-06-02 16:18:04 +02006 */
7
8#include <common.h>
Stefan Roeseb36df562010-09-09 19:18:00 +02009#include <asm/ppc4xx.h>
Heiko Schocher566a4942007-06-22 19:11:54 +020010#include <malloc.h>
11#include <command.h>
12#include <crc.h>
Stefan Roesea4c8d132006-06-02 16:18:04 +020013#include <asm/processor.h>
14#include <spd_sdram.h>
Heiko Schocher566a4942007-06-22 19:11:54 +020015#include <status_led.h>
16#include <sha1.h>
Heiko Schocherf98984c2007-08-28 17:39:14 +020017#include <asm/io.h>
Wolfgang Denkd2567be2009-03-28 20:16:16 +010018#include <net.h>
Pavel Herrmann21d2bf42012-10-07 05:56:13 +000019#include <ata.h>
Stefan Roesea4c8d132006-06-02 16:18:04 +020020
21DECLARE_GLOBAL_DATA_PTR;
22
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020023extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
Stefan Roesea4c8d132006-06-02 16:18:04 +020024
Heiko Schocher566a4942007-06-22 19:11:54 +020025unsigned char sha1_checksum[SHA1_SUM_LEN];
26
27/* swap 4 Bits (Bit0 = Bit3, Bit1 = Bit2, Bit2 = Bit1 and Bit3 = Bit0) */
28unsigned char swapbits[16] = {0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
29 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf};
30
31static void set_leds (int val)
Stefan Roesea4c8d132006-06-02 16:18:04 +020032{
Heiko Schocher566a4942007-06-22 19:11:54 +020033 out32(GPIO0_OR, (in32 (GPIO0_OR) & ~0x78000000) | (val << 27));
Stefan Roesea4c8d132006-06-02 16:18:04 +020034}
35
Heiko Schocher566a4942007-06-22 19:11:54 +020036#define GET_LEDS ((in32 (GPIO0_OR) & 0x78000000) >> 27)
37
38void __led_init (led_id_t mask, int state)
39{
40 int val = GET_LEDS;
41
42 if (state == STATUS_LED_ON)
43 val |= mask;
44 else
45 val &= ~mask;
46 set_leds (val);
47}
48
49void __led_set (led_id_t mask, int state)
50{
51 int val = GET_LEDS;
52
53 if (state == STATUS_LED_ON)
54 val |= mask;
55 else if (state == STATUS_LED_OFF)
56 val &= ~mask;
57 set_leds (val);
58}
59
60void __led_toggle (led_id_t mask)
61{
62 int val = GET_LEDS;
63
64 val ^= mask;
65 set_leds (val);
66}
67
68static void status_led_blink (void)
69{
70 int i;
71 int val = GET_LEDS;
72
73 /* set all LED which are on, to state BLINKING */
74 for (i = 0; i < 4; i++) {
Heiko Schocher96e1d752007-07-11 18:39:11 +020075 if (val & 0x01) status_led_set (3 - i, STATUS_LED_BLINKING);
76 else status_led_set (3 - i, STATUS_LED_OFF);
77 val = val >> 1;
Heiko Schocher566a4942007-06-22 19:11:54 +020078 }
79}
80
81#if defined(CONFIG_SHOW_BOOT_PROGRESS)
82void show_boot_progress (int val)
83{
84 /* find all valid Codes for val in README */
Simon Glass8ade9502011-12-10 11:07:58 +000085 if (val == -BOOTSTAGE_ID_NEED_RESET)
86 return;
Heiko Schocher566a4942007-06-22 19:11:54 +020087 if (val < 0) {
88 /* smthing goes wrong */
89 status_led_blink ();
90 return;
91 }
92 switch (val) {
Simon Glass5dc88712012-01-14 15:24:47 +000093 case BOOTSTAGE_ID_CHECK_MAGIC:
94 /* validating Image */
95 status_led_set(0, STATUS_LED_OFF);
96 status_led_set(1, STATUS_LED_ON);
97 status_led_set(2, STATUS_LED_ON);
98 break;
99 case BOOTSTAGE_ID_RUN_OS:
100 status_led_set(0, STATUS_LED_ON);
101 status_led_set(1, STATUS_LED_ON);
102 status_led_set(2, STATUS_LED_ON);
103 break;
Heiko Schocher96e1d752007-07-11 18:39:11 +0200104#if 0
Simon Glassc8e66db2012-01-14 15:24:52 +0000105 case BOOTSTAGE_ID_NET_ETH_START:
106 /* starting Ethernet configuration */
107 status_led_set(0, STATUS_LED_OFF);
108 status_led_set(1, STATUS_LED_OFF);
109 status_led_set(2, STATUS_LED_ON);
110 break;
Heiko Schocher96e1d752007-07-11 18:39:11 +0200111#endif
Simon Glassc8e66db2012-01-14 15:24:52 +0000112 case BOOTSTAGE_ID_NET_START:
113 /* loading Image */
114 status_led_set(0, STATUS_LED_ON);
115 status_led_set(1, STATUS_LED_OFF);
116 status_led_set(2, STATUS_LED_ON);
117 break;
Heiko Schocher566a4942007-06-22 19:11:54 +0200118 }
119}
120#endif
121
Stefan Roesea4c8d132006-06-02 16:18:04 +0200122int board_early_init_f(void)
123{
124 register uint reg;
125
126 set_leds(0); /* display boot info counter */
127
128 /*--------------------------------------------------------------------
129 * Setup the external bus controller/chip selects
130 *-------------------------------------------------------------------*/
Stefan Roesed1c3b272009-09-09 16:25:29 +0200131 mtdcr(EBC0_CFGADDR, EBC0_CFG);
132 reg = mfdcr(EBC0_CFGDATA);
133 mtdcr(EBC0_CFGDATA, reg | 0x04000000); /* Set ATC */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200134
135 /*--------------------------------------------------------------------
Stefan Roesea47a12b2010-04-15 16:07:28 +0200136 * GPIO's are alreay setup in arch/powerpc/cpu/ppc4xx/cpu_init.c
Stefan Roesea4c8d132006-06-02 16:18:04 +0200137 * via define from board config file.
138 *-------------------------------------------------------------------*/
139
140 /*--------------------------------------------------------------------
141 * Setup the interrupt controller polarities, triggers, etc.
142 *-------------------------------------------------------------------*/
Stefan Roese952e7762009-09-24 09:55:50 +0200143 mtdcr(UIC0SR, 0xffffffff); /* clear all */
144 mtdcr(UIC0ER, 0x00000000); /* disable all */
145 mtdcr(UIC0CR, 0x00000001); /* UIC1 crit is critical */
146 mtdcr(UIC0PR, 0xfffffe1f); /* per ref-board manual */
147 mtdcr(UIC0TR, 0x01c00000); /* per ref-board manual */
148 mtdcr(UIC0VR, 0x00000001); /* int31 highest, base=0x000 */
149 mtdcr(UIC0SR, 0xffffffff); /* clear all */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200150
Stefan Roese952e7762009-09-24 09:55:50 +0200151 mtdcr(UIC1SR, 0xffffffff); /* clear all */
152 mtdcr(UIC1ER, 0x00000000); /* disable all */
153 mtdcr(UIC1CR, 0x00000000); /* all non-critical */
154 mtdcr(UIC1PR, 0xffffe0ff); /* per ref-board manual */
155 mtdcr(UIC1TR, 0x00ffc000); /* per ref-board manual */
156 mtdcr(UIC1VR, 0x00000001); /* int31 highest, base=0x000 */
157 mtdcr(UIC1SR, 0xffffffff); /* clear all */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200158
159 /*--------------------------------------------------------------------
160 * Setup other serial configuration
161 *-------------------------------------------------------------------*/
Stefan Roesed1c3b272009-09-09 16:25:29 +0200162 mfsdr(SDR0_PCI0, reg);
163 mtsdr(SDR0_PCI0, 0x80000000 | reg); /* PCI arbiter enabled */
164 mtsdr(SDR0_PFC0, 0x00000000); /* Pin function: enable GPIO49-63 */
165 mtsdr(SDR0_PFC1, 0x00048000); /* Pin function: UART0 has 4 pins, select IRQ5 */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200166
167 return 0;
168}
169
Heiko Schocher566a4942007-06-22 19:11:54 +0200170#define EEPROM_LEN 256
Mike Frysinger9c150102009-02-11 20:09:52 -0500171static void load_ethaddr(void)
Heiko Schocher566a4942007-06-22 19:11:54 +0200172{
Mike Frysinger9c150102009-02-11 20:09:52 -0500173 int ok_ethaddr, ok_eth1addr;
Heiko Schocher566a4942007-06-22 19:11:54 +0200174 int ret;
Wolfgang Denkd2567be2009-03-28 20:16:16 +0100175 uchar buf[EEPROM_LEN];
Heiko Schocher566a4942007-06-22 19:11:54 +0200176 char *use_eeprom;
177 u16 checksumcrc16 = 0;
178
Mike Frysinger9c150102009-02-11 20:09:52 -0500179 /* If the env is sane, then nothing for us to do */
180 ok_ethaddr = eth_getenv_enetaddr("ethaddr", buf);
181 ok_eth1addr = eth_getenv_enetaddr("eth1addr", buf);
182 if (ok_ethaddr && ok_eth1addr)
183 return;
184
Heiko Schocher566a4942007-06-22 19:11:54 +0200185 /* read the MACs from EEprom */
186 status_led_set (0, STATUS_LED_ON);
187 status_led_set (1, STATUS_LED_ON);
Wolfgang Denkd2567be2009-03-28 20:16:16 +0100188 ret = eeprom_read (CONFIG_SYS_I2C_EEPROM_ADDR, 0, buf, EEPROM_LEN);
Heiko Schocher566a4942007-06-22 19:11:54 +0200189 if (ret == 0) {
Wolfgang Denkd2567be2009-03-28 20:16:16 +0100190 checksumcrc16 = cyg_crc16 (buf, EEPROM_LEN - 2);
Heiko Schocher566a4942007-06-22 19:11:54 +0200191 /* check, if the EEprom is programmed:
192 * - The Prefix(Byte 0,1,2) is equal to "ATR"
193 * - The checksum, stored in the last 2 Bytes, is correct
194 */
Wolfgang Denkd2567be2009-03-28 20:16:16 +0100195 if ((strncmp ((char *)buf,"ATR",3) != 0) ||
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200196 ((checksumcrc16 >> 8) != buf[EEPROM_LEN - 2]) ||
197 ((checksumcrc16 & 0xff) != buf[EEPROM_LEN - 1])) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200198 /* EEprom is not programmed */
199 printf("%s: EEPROM Checksum not OK\n", __FUNCTION__);
200 } else {
201 /* get the MACs */
Mike Frysinger9c150102009-02-11 20:09:52 -0500202 if (!ok_ethaddr)
203 eth_setenv_enetaddr("ethaddr", &buf[3]);
204 if (!ok_eth1addr)
205 eth_setenv_enetaddr("eth1addr", &buf[9]);
Heiko Schocher566a4942007-06-22 19:11:54 +0200206 return;
207 }
208 }
209
210 /* some error reading the EEprom */
211 if ((use_eeprom = getenv ("use_eeprom_ethaddr")) == NULL) {
212 /* dont use bootcmd */
213 setenv("bootdelay", "-1");
214 return;
215 }
216 /* == default ? use standard */
217 if (strncmp (use_eeprom, "default", 7) == 0) {
218 return;
219 }
220 /* Env doesnt exist -> hang */
221 status_led_blink ();
Heiko Schocher90790242007-07-13 08:26:05 +0200222 /* here we do this "handy" because we have no interrupts
223 at this time */
224 puts ("### EEPROM ERROR ### Please RESET the board ###\n");
225 for (;;) {
226 __led_toggle (12);
227 udelay (100000);
228 }
Heiko Schocher566a4942007-06-22 19:11:54 +0200229 return;
230}
231
232#ifdef CONFIG_PREBOOT
233
234static uchar kbd_magic_prefix[] = "key_magic";
235static uchar kbd_command_prefix[] = "key_cmd";
236
237struct kbd_data_t {
238 char s1;
239 char s2;
240};
241
242struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
243{
244 char *val;
245 unsigned long tmp;
246
247 /* use the DIPs for some bootoptions */
248 val = getenv (ENV_NAME_DIP);
249 tmp = simple_strtoul (val, NULL, 16);
250
251 kbd_data->s2 = (tmp & 0x0f);
252 kbd_data->s1 = (tmp & 0xf0) >> 4;
253 return kbd_data;
254}
255
256static int compare_magic (const struct kbd_data_t *kbd_data, char *str)
257{
258 char s1 = str[0];
259
260 if (s1 >= '0' && s1 <= '9')
261 s1 -= '0';
262 else if (s1 >= 'a' && s1 <= 'f')
263 s1 = s1 - 'a' + 10;
264 else if (s1 >= 'A' && s1 <= 'F')
265 s1 = s1 - 'A' + 10;
266 else
267 return -1;
268
269 if (s1 != kbd_data->s1) return -1;
270
271 s1 = str[1];
272 if (s1 >= '0' && s1 <= '9')
273 s1 -= '0';
274 else if (s1 >= 'a' && s1 <= 'f')
275 s1 = s1 - 'a' + 10;
276 else if (s1 >= 'A' && s1 <= 'F')
277 s1 = s1 - 'A' + 10;
278 else
279 return -1;
280
281 if (s1 != kbd_data->s2) return -1;
282 return 0;
283}
284
285static char *key_match (const struct kbd_data_t *kbd_data)
286{
287 char magic[sizeof (kbd_magic_prefix) + 1];
288 char *suffix;
289 char *kbd_magic_keys;
290
291 /*
292 * The following string defines the characters that can be appended
293 * to "key_magic" to form the names of environment variables that
294 * hold "magic" key codes, i. e. such key codes that can cause
295 * pre-boot actions. If the string is empty (""), then only
296 * "key_magic" is checked (old behaviour); the string "125" causes
297 * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
298 */
299 if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
300 kbd_magic_keys = "";
301
302 /* loop over all magic keys;
303 * use '\0' suffix in case of empty string
304 */
305 for (suffix = kbd_magic_keys; *suffix ||
306 suffix == kbd_magic_keys; ++suffix) {
307 sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
308 if (compare_magic (kbd_data, getenv (magic)) == 0) {
309 char cmd_name[sizeof (kbd_command_prefix) + 1];
310 char *cmd;
311
312 sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
313 cmd = getenv (cmd_name);
314
315 return (cmd);
316 }
317 }
318 return (NULL);
319}
320
321#endif /* CONFIG_PREBOOT */
322
323static int pcs440ep_readinputs (void)
324{
325 int i;
326 char value[20];
327
328 /* read the inputs and set the Envvars */
329 /* Revision Level Bit 26 - 29 */
330 i = ((in32 (GPIO0_IR) & 0x0000003c) >> 2);
331 i = swapbits[i];
332 sprintf (value, "%02x", i);
333 setenv (ENV_NAME_REVLEV, value);
334 /* Solder Switch Bit 30 - 33 */
335 i = (in32 (GPIO0_IR) & 0x00000003) << 2;
336 i += (in32 (GPIO1_IR) & 0xc0000000) >> 30;
337 i = swapbits[i];
338 sprintf (value, "%02x", i);
339 setenv (ENV_NAME_SOLDER, value);
340 /* DIP Switch Bit 49 - 56 */
341 i = ((in32 (GPIO1_IR) & 0x00007f80) >> 7);
342 i = (swapbits[i & 0x0f] << 4) + swapbits[(i & 0xf0) >> 4];
343 sprintf (value, "%02x", i);
344 setenv (ENV_NAME_DIP, value);
345 return 0;
346}
347
348
349#if defined(CONFIG_SHA1_CHECK_UB_IMG)
350/*************************************************************************
351 * calculate a SHA1 sum for the U-Boot image in Flash.
352 *
353 ************************************************************************/
354static int pcs440ep_sha1 (int docheck)
355{
356 unsigned char *data;
357 unsigned char *ptroff;
358 unsigned char output[20];
359 unsigned char org[20];
360 int i, len = CONFIG_SHA1_LEN;
361
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200362 memcpy ((char *)CONFIG_SYS_LOAD_ADDR, (char *)CONFIG_SHA1_START, len);
363 data = (unsigned char *)CONFIG_SYS_LOAD_ADDR;
Heiko Schocher566a4942007-06-22 19:11:54 +0200364 ptroff = &data[len + SHA1_SUM_POS];
365
366 for (i = 0; i < SHA1_SUM_LEN; i++) {
367 org[i] = ptroff[i];
368 ptroff[i] = 0;
369 }
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200370
Heiko Schocher566a4942007-06-22 19:11:54 +0200371 sha1_csum ((unsigned char *) data, len, (unsigned char *)output);
372
373 if (docheck == 2) {
374 for (i = 0; i < 20 ; i++) {
375 printf("%02X ", output[i]);
376 }
377 printf("\n");
378 }
379 if (docheck == 1) {
380 for (i = 0; i < 20 ; i++) {
381 if (org[i] != output[i]) return 1;
382 }
383 }
384 return 0;
385}
386
387/*************************************************************************
388 * do some checks after the SHA1 checksum from the U-Boot Image was
389 * calculated.
390 *
391 ************************************************************************/
392static void pcs440ep_checksha1 (void)
393{
394 int ret;
395 char *cs_test;
396
Heiko Schocher96e1d752007-07-11 18:39:11 +0200397 status_led_set (0, STATUS_LED_OFF);
398 status_led_set (1, STATUS_LED_OFF);
399 status_led_set (2, STATUS_LED_ON);
Heiko Schocher566a4942007-06-22 19:11:54 +0200400 ret = pcs440ep_sha1 (1);
401 if (ret == 0) return;
402
403 if ((cs_test = getenv ("cs_test")) == NULL) {
404 /* Env doesnt exist -> hang */
405 status_led_blink ();
Heiko Schocher90790242007-07-13 08:26:05 +0200406 /* here we do this "handy" because we have no interrupts
407 at this time */
408 puts ("### SHA1 ERROR ### Please RESET the board ###\n");
409 for (;;) {
410 __led_toggle (2);
411 udelay (100000);
412 }
Heiko Schocher566a4942007-06-22 19:11:54 +0200413 }
414
415 if (strncmp (cs_test, "off", 3) == 0) {
416 printf ("SHA1 U-Boot sum NOT ok!\n");
417 setenv ("bootdelay", "-1");
418 }
419}
420#else
421static __inline__ void pcs440ep_checksha1 (void) { do {} while (0);}
422#endif
423
Stefan Roesea4c8d132006-06-02 16:18:04 +0200424int misc_init_r (void)
425{
426 uint pbcr;
427 int size_val = 0;
428
Mike Frysinger9c150102009-02-11 20:09:52 -0500429 load_ethaddr();
430
Stefan Roesea4c8d132006-06-02 16:18:04 +0200431 /* Re-do sizing to get full correct info */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200432 mtdcr(EBC0_CFGADDR, PB0CR);
433 pbcr = mfdcr(EBC0_CFGDATA);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200434 switch (gd->bd->bi_flashsize) {
435 case 1 << 20:
436 size_val = 0;
437 break;
438 case 2 << 20:
439 size_val = 1;
440 break;
441 case 4 << 20:
442 size_val = 2;
443 break;
444 case 8 << 20:
445 size_val = 3;
446 break;
447 case 16 << 20:
448 size_val = 4;
449 break;
450 case 32 << 20:
451 size_val = 5;
452 break;
453 case 64 << 20:
454 size_val = 6;
455 break;
456 case 128 << 20:
457 size_val = 7;
458 break;
459 }
460 pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
Stefan Roesed1c3b272009-09-09 16:25:29 +0200461 mtdcr(EBC0_CFGADDR, PB0CR);
462 mtdcr(EBC0_CFGDATA, pbcr);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200463
464 /* adjust flash start and offset */
465 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
466 gd->bd->bi_flashoffset = 0;
467
468 /* Monitor protection ON by default */
469 (void)flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200470 -CONFIG_SYS_MONITOR_LEN,
Stefan Roesea4c8d132006-06-02 16:18:04 +0200471 0xffffffff,
472 &flash_info[1]);
473
474 /* Env protection ON by default */
475 (void)flash_protect(FLAG_PROTECT_SET,
Jean-Christophe PLAGNIOL-VILLARD0e8d1582008-09-10 22:48:06 +0200476 CONFIG_ENV_ADDR_REDUND,
477 CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1,
Stefan Roese4526c872006-06-06 10:59:12 +0200478 &flash_info[1]);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200479
Heiko Schocher566a4942007-06-22 19:11:54 +0200480 pcs440ep_readinputs ();
481 pcs440ep_checksha1 ();
482#ifdef CONFIG_PREBOOT
483 {
484 struct kbd_data_t kbd_data;
485 /* Decode keys */
486 char *str = strdup (key_match (get_keys (&kbd_data)));
487 /* Set or delete definition */
488 setenv ("preboot", str);
489 free (str);
490 }
491#endif /* CONFIG_PREBOOT */
Stefan Roesea4c8d132006-06-02 16:18:04 +0200492 return 0;
493}
494
495int checkboard(void)
496{
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000497 char buf[64];
498 int i = getenv_f("serial#", buf, sizeof(buf));
Stefan Roesea4c8d132006-06-02 16:18:04 +0200499
500 printf("Board: PCS440EP");
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000501 if (i > 0) {
Stefan Roesea4c8d132006-06-02 16:18:04 +0200502 puts(", serial# ");
Wolfgang Denkf0c0b3a2011-05-04 10:32:28 +0000503 puts(buf);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200504 }
505 putc('\n');
506
507 return (0);
508}
509
Heiko Schocher566a4942007-06-22 19:11:54 +0200510void spd_ddr_init_hang (void)
511{
512 status_led_set (0, STATUS_LED_OFF);
513 status_led_set (1, STATUS_LED_ON);
514 /* we cannot use hang() because we are still running from
515 Flash, and so the status_led driver is not initialized */
Heiko Schocher90790242007-07-13 08:26:05 +0200516 puts ("### SDRAM ERROR ### Please RESET the board ###\n");
Heiko Schocher566a4942007-06-22 19:11:54 +0200517 for (;;) {
518 __led_toggle (4);
519 udelay (100000);
520 }
521}
Heiko Schocher566a4942007-06-22 19:11:54 +0200522
Becky Bruce9973e3c2008-06-09 16:03:40 -0500523phys_size_t initdram (int board_type)
Stefan Roesea4c8d132006-06-02 16:18:04 +0200524{
525 long dram_size = 0;
526
Heiko Schocher566a4942007-06-22 19:11:54 +0200527 status_led_set (0, STATUS_LED_ON);
528 status_led_set (1, STATUS_LED_OFF);
Stefan Roesea4c8d132006-06-02 16:18:04 +0200529 dram_size = spd_sdram();
Heiko Schocher566a4942007-06-22 19:11:54 +0200530 status_led_set (0, STATUS_LED_OFF);
531 status_led_set (1, STATUS_LED_ON);
532 if (dram_size == 0) {
533 hang();
534 }
Stefan Roesea4c8d132006-06-02 16:18:04 +0200535
536 return dram_size;
537}
538
Stefan Roesea4c8d132006-06-02 16:18:04 +0200539/*************************************************************************
Stefan Roesea4c8d132006-06-02 16:18:04 +0200540 * hw_watchdog_reset
541 *
542 * This routine is called to reset (keep alive) the watchdog timer
543 *
544 ************************************************************************/
545#if defined(CONFIG_HW_WATCHDOG)
546void hw_watchdog_reset(void)
547{
548
549}
550#endif
Heiko Schocher566a4942007-06-22 19:11:54 +0200551
552/*************************************************************************
553 * "led" Commando for the U-Boot shell
554 *
555 ************************************************************************/
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200556int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Heiko Schocher566a4942007-06-22 19:11:54 +0200557{
Heiko Schocher96e1d752007-07-11 18:39:11 +0200558 int rcode = 0, i;
Heiko Schocher566a4942007-06-22 19:11:54 +0200559 ulong pattern = 0;
560
Heiko Schocher96e1d752007-07-11 18:39:11 +0200561 pattern = simple_strtoul (argv[1], NULL, 16);
562 if (pattern > 0x400) {
563 int val = GET_LEDS;
564 printf ("led: %x\n", val);
565 return rcode;
566 }
567 if (pattern > 0x200) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200568 status_led_blink ();
569 hang ();
570 return rcode;
571 }
Heiko Schocher96e1d752007-07-11 18:39:11 +0200572 if (pattern > 0x100) {
Heiko Schocher566a4942007-06-22 19:11:54 +0200573 status_led_blink ();
574 return rcode;
575 }
576 pattern &= 0x0f;
Heiko Schocher96e1d752007-07-11 18:39:11 +0200577 for (i = 0; i < 4; i++) {
578 if (pattern & 0x01) status_led_set (i, STATUS_LED_ON);
579 else status_led_set (i, STATUS_LED_OFF);
580 pattern = pattern >> 1;
581 }
Heiko Schocher566a4942007-06-22 19:11:54 +0200582 return rcode;
583}
584
585U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200586 led, 2, 1, do_led,
Peter Tyser2fb26042009-01-27 18:03:12 -0600587 "set the DIAG-LED",
Heiko Schocher96e1d752007-07-11 18:39:11 +0200588 "[bitmask] 0x01 = DIAG 1 on\n"
589 " 0x02 = DIAG 2 on\n"
590 " 0x04 = DIAG 3 on\n"
591 " 0x08 = DIAG 4 on\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200592 " > 0x100 set the LED, who are on, to state blinking"
Heiko Schocher566a4942007-06-22 19:11:54 +0200593);
594
595#if defined(CONFIG_SHA1_CHECK_UB_IMG)
596/*************************************************************************
597 * "sha1" Commando for the U-Boot shell
598 *
599 ************************************************************************/
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200600int do_sha1 (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Heiko Schocher566a4942007-06-22 19:11:54 +0200601{
602 int rcode = -1;
603
604 if (argc < 2) {
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200605usage:
606 return cmd_usage(cmdtp);
Heiko Schocher566a4942007-06-22 19:11:54 +0200607 }
608
609 if (argc >= 3) {
610 unsigned char *data;
611 unsigned char output[20];
612 int len;
613 int i;
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200614
Heiko Schocher566a4942007-06-22 19:11:54 +0200615 data = (unsigned char *)simple_strtoul (argv[1], NULL, 16);
616 len = simple_strtoul (argv[2], NULL, 16);
617 sha1_csum (data, len, (unsigned char *)output);
618 printf ("U-Boot sum:\n");
619 for (i = 0; i < 20 ; i++) {
620 printf ("%02X ", output[i]);
621 }
622 printf ("\n");
623 if (argc == 4) {
624 data = (unsigned char *)simple_strtoul (argv[3], NULL, 16);
625 memcpy (data, output, 20);
626 }
627 return 0;
628 }
629 if (argc == 2) {
630 char *ptr = argv[1];
631 if (*ptr != '-') goto usage;
632 ptr++;
633 if ((*ptr == 'c') || (*ptr == 'C')) {
634 rcode = pcs440ep_sha1 (1);
635 printf ("SHA1 U-Boot sum %sok!\n", (rcode != 0) ? "not " : "");
636 } else if ((*ptr == 'p') || (*ptr == 'P')) {
637 rcode = pcs440ep_sha1 (2);
638 } else {
639 rcode = pcs440ep_sha1 (0);
640 }
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200641 return rcode;
Heiko Schocher566a4942007-06-22 19:11:54 +0200642 }
643 return rcode;
644}
645
646U_BOOT_CMD(
Wolfgang Denk53677ef2008-05-20 16:00:29 +0200647 sha1, 4, 1, do_sha1,
Peter Tyser2fb26042009-01-27 18:03:12 -0600648 "calculate the SHA1 Sum",
Heiko Schocher566a4942007-06-22 19:11:54 +0200649 "address len [addr] calculate the SHA1 sum [save at addr]\n"
650 " -p calculate the SHA1 sum from the U-Boot image in flash and print\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200651 " -c check the U-Boot image in flash"
Heiko Schocher566a4942007-06-22 19:11:54 +0200652);
653#endif
654
Heiko Schocherf98984c2007-08-28 17:39:14 +0200655#if defined (CONFIG_CMD_IDE)
656/* These addresses need to be shifted one place to the left
657 * ( bus per_addr 20 -30 is connectsd on CF bus A10-A0)
658 * These values are shifted
659 */
Heiko Schocherf98984c2007-08-28 17:39:14 +0200660void inline ide_outb(int dev, int port, unsigned char val)
661{
662 debug ("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
663 dev, port, val, (ATA_CURR_BASE(dev)+port));
664
665 out_be16((u16 *)(ATA_CURR_BASE(dev)+(port << 1)), val);
666}
667unsigned char inline ide_inb(int dev, int port)
668{
669 uchar val;
670 val = in_be16((u16 *)(ATA_CURR_BASE(dev)+(port << 1)));
671 debug ("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
672 dev, port, (ATA_CURR_BASE(dev)+port), val);
673 return (val);
674}
675#endif
676
Heiko Schocher566a4942007-06-22 19:11:54 +0200677#ifdef CONFIG_IDE_PREINIT
678int ide_preinit (void)
679{
680 /* Set True IDE Mode */
681 out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00100000));
682 out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
683 out32 (GPIO1_OR, (in32 (GPIO1_OR) & ~0x00008040));
684 udelay (100000);
685 return 0;
686}
687#endif
688
Wolfgang Denkafaac862007-08-12 14:27:39 +0200689#if defined (CONFIG_CMD_IDE) && defined (CONFIG_IDE_RESET)
Heiko Schocher566a4942007-06-22 19:11:54 +0200690void ide_set_reset (int idereset)
691{
692 debug ("ide_reset(%d)\n", idereset);
693 if (idereset == 0) {
694 out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
695 } else {
696 out32 (GPIO0_OR, (in32 (GPIO0_OR) & ~0x00200000));
697 }
698 udelay (10000);
699}
Wolfgang Denkafaac862007-08-12 14:27:39 +0200700#endif /* defined (CONFIG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
Pavel Herrmann21d2bf42012-10-07 05:56:13 +0000701
702
703/* this is motly the same as it should, causing a little code duplication */
704#if defined(CONFIG_CMD_IDE)
705#define EIEIO __asm__ volatile ("eieio")
706
707void ide_input_swap_data(int dev, ulong *sect_buf, int words)
708{
709 volatile ushort *pbuf =
710 (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
711 ushort *dbuf = (ushort *) sect_buf;
712
713 debug("in input swap data base for read is %lx\n",
714 (unsigned long) pbuf);
715
716 while (words--) {
717 *dbuf++ = *pbuf;
718 *dbuf++ = *pbuf;
719 }
720}
721
722void ide_output_data(int dev, const ulong *sect_buf, int words)
723{
724 ushort *dbuf;
725 volatile ushort *pbuf;
726
727 pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
728 dbuf = (ushort *) sect_buf;
729 while (words--) {
730 EIEIO;
731 *pbuf = ld_le16(dbuf++);
732 EIEIO;
733 *pbuf = ld_le16(dbuf++);
734 }
735}
736
737void ide_input_data(int dev, ulong *sect_buf, int words)
738{
739 ushort *dbuf;
740 volatile ushort *pbuf;
741
742 pbuf = (ushort *) (ATA_CURR_BASE(dev) + ATA_DATA_REG);
743 dbuf = (ushort *) sect_buf;
744
745 debug("in input data base for read is %lx\n", (unsigned long) pbuf);
746
747 while (words--) {
748 EIEIO;
749 *dbuf++ = ld_le16(pbuf);
750 EIEIO;
751 *dbuf++ = ld_le16(pbuf);
752 }
753}
754
755#endif