Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2006 |
| 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Stefan Roese | b36df56 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 9 | #include <asm/ppc4xx.h> |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 10 | #include <malloc.h> |
| 11 | #include <command.h> |
| 12 | #include <crc.h> |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 13 | #include <asm/processor.h> |
| 14 | #include <spd_sdram.h> |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 15 | #include <status_led.h> |
| 16 | #include <sha1.h> |
Heiko Schocher | f98984c | 2007-08-28 17:39:14 +0200 | [diff] [blame] | 17 | #include <asm/io.h> |
Wolfgang Denk | d2567be | 2009-03-28 20:16:16 +0100 | [diff] [blame] | 18 | #include <net.h> |
Pavel Herrmann | 21d2bf4 | 2012-10-07 05:56:13 +0000 | [diff] [blame] | 19 | #include <ata.h> |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 23 | extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */ |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 24 | |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 25 | unsigned char sha1_checksum[SHA1_SUM_LEN]; |
| 26 | |
| 27 | /* swap 4 Bits (Bit0 = Bit3, Bit1 = Bit2, Bit2 = Bit1 and Bit3 = Bit0) */ |
| 28 | unsigned char swapbits[16] = {0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe, |
| 29 | 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf}; |
| 30 | |
| 31 | static void set_leds (int val) |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 32 | { |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 33 | out32(GPIO0_OR, (in32 (GPIO0_OR) & ~0x78000000) | (val << 27)); |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 34 | } |
| 35 | |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 36 | #define GET_LEDS ((in32 (GPIO0_OR) & 0x78000000) >> 27) |
| 37 | |
| 38 | void __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 | |
| 49 | void __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 | |
| 60 | void __led_toggle (led_id_t mask) |
| 61 | { |
| 62 | int val = GET_LEDS; |
| 63 | |
| 64 | val ^= mask; |
| 65 | set_leds (val); |
| 66 | } |
| 67 | |
| 68 | static 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 Schocher | 96e1d75 | 2007-07-11 18:39:11 +0200 | [diff] [blame] | 75 | 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 Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | |
| 81 | #if defined(CONFIG_SHOW_BOOT_PROGRESS) |
| 82 | void show_boot_progress (int val) |
| 83 | { |
| 84 | /* find all valid Codes for val in README */ |
Simon Glass | 8ade950 | 2011-12-10 11:07:58 +0000 | [diff] [blame] | 85 | if (val == -BOOTSTAGE_ID_NEED_RESET) |
| 86 | return; |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 87 | if (val < 0) { |
| 88 | /* smthing goes wrong */ |
| 89 | status_led_blink (); |
| 90 | return; |
| 91 | } |
| 92 | switch (val) { |
Simon Glass | 5dc8871 | 2012-01-14 15:24:47 +0000 | [diff] [blame] | 93 | 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 Schocher | 96e1d75 | 2007-07-11 18:39:11 +0200 | [diff] [blame] | 104 | #if 0 |
Simon Glass | c8e66db | 2012-01-14 15:24:52 +0000 | [diff] [blame] | 105 | 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 Schocher | 96e1d75 | 2007-07-11 18:39:11 +0200 | [diff] [blame] | 111 | #endif |
Simon Glass | c8e66db | 2012-01-14 15:24:52 +0000 | [diff] [blame] | 112 | 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 Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | #endif |
| 121 | |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 122 | int 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 Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 131 | mtdcr(EBC0_CFGADDR, EBC0_CFG); |
| 132 | reg = mfdcr(EBC0_CFGDATA); |
| 133 | mtdcr(EBC0_CFGDATA, reg | 0x04000000); /* Set ATC */ |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 134 | |
| 135 | /*-------------------------------------------------------------------- |
Stefan Roese | a47a12b | 2010-04-15 16:07:28 +0200 | [diff] [blame] | 136 | * GPIO's are alreay setup in arch/powerpc/cpu/ppc4xx/cpu_init.c |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 137 | * via define from board config file. |
| 138 | *-------------------------------------------------------------------*/ |
| 139 | |
| 140 | /*-------------------------------------------------------------------- |
| 141 | * Setup the interrupt controller polarities, triggers, etc. |
| 142 | *-------------------------------------------------------------------*/ |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 143 | 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 Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 150 | |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 151 | 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 Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 158 | |
| 159 | /*-------------------------------------------------------------------- |
| 160 | * Setup other serial configuration |
| 161 | *-------------------------------------------------------------------*/ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 162 | 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 Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 170 | #define EEPROM_LEN 256 |
Mike Frysinger | 9c15010 | 2009-02-11 20:09:52 -0500 | [diff] [blame] | 171 | static void load_ethaddr(void) |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 172 | { |
Mike Frysinger | 9c15010 | 2009-02-11 20:09:52 -0500 | [diff] [blame] | 173 | int ok_ethaddr, ok_eth1addr; |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 174 | int ret; |
Wolfgang Denk | d2567be | 2009-03-28 20:16:16 +0100 | [diff] [blame] | 175 | uchar buf[EEPROM_LEN]; |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 176 | char *use_eeprom; |
| 177 | u16 checksumcrc16 = 0; |
| 178 | |
Mike Frysinger | 9c15010 | 2009-02-11 20:09:52 -0500 | [diff] [blame] | 179 | /* 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 Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 185 | /* read the MACs from EEprom */ |
| 186 | status_led_set (0, STATUS_LED_ON); |
| 187 | status_led_set (1, STATUS_LED_ON); |
Wolfgang Denk | d2567be | 2009-03-28 20:16:16 +0100 | [diff] [blame] | 188 | ret = eeprom_read (CONFIG_SYS_I2C_EEPROM_ADDR, 0, buf, EEPROM_LEN); |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 189 | if (ret == 0) { |
Wolfgang Denk | d2567be | 2009-03-28 20:16:16 +0100 | [diff] [blame] | 190 | checksumcrc16 = cyg_crc16 (buf, EEPROM_LEN - 2); |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 191 | /* 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 Denk | d2567be | 2009-03-28 20:16:16 +0100 | [diff] [blame] | 195 | if ((strncmp ((char *)buf,"ATR",3) != 0) || |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 196 | ((checksumcrc16 >> 8) != buf[EEPROM_LEN - 2]) || |
| 197 | ((checksumcrc16 & 0xff) != buf[EEPROM_LEN - 1])) { |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 198 | /* EEprom is not programmed */ |
| 199 | printf("%s: EEPROM Checksum not OK\n", __FUNCTION__); |
| 200 | } else { |
| 201 | /* get the MACs */ |
Mike Frysinger | 9c15010 | 2009-02-11 20:09:52 -0500 | [diff] [blame] | 202 | if (!ok_ethaddr) |
| 203 | eth_setenv_enetaddr("ethaddr", &buf[3]); |
| 204 | if (!ok_eth1addr) |
| 205 | eth_setenv_enetaddr("eth1addr", &buf[9]); |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 206 | 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 Schocher | 9079024 | 2007-07-13 08:26:05 +0200 | [diff] [blame] | 222 | /* 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 Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 229 | return; |
| 230 | } |
| 231 | |
| 232 | #ifdef CONFIG_PREBOOT |
| 233 | |
| 234 | static uchar kbd_magic_prefix[] = "key_magic"; |
| 235 | static uchar kbd_command_prefix[] = "key_cmd"; |
| 236 | |
| 237 | struct kbd_data_t { |
| 238 | char s1; |
| 239 | char s2; |
| 240 | }; |
| 241 | |
| 242 | struct 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 | |
| 256 | static 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 | |
| 285 | static 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 | |
| 323 | static 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 | ************************************************************************/ |
| 354 | static 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-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 362 | memcpy ((char *)CONFIG_SYS_LOAD_ADDR, (char *)CONFIG_SHA1_START, len); |
| 363 | data = (unsigned char *)CONFIG_SYS_LOAD_ADDR; |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 364 | 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 Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 370 | |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 371 | 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 | ************************************************************************/ |
| 392 | static void pcs440ep_checksha1 (void) |
| 393 | { |
| 394 | int ret; |
| 395 | char *cs_test; |
| 396 | |
Heiko Schocher | 96e1d75 | 2007-07-11 18:39:11 +0200 | [diff] [blame] | 397 | status_led_set (0, STATUS_LED_OFF); |
| 398 | status_led_set (1, STATUS_LED_OFF); |
| 399 | status_led_set (2, STATUS_LED_ON); |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 400 | 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 Schocher | 9079024 | 2007-07-13 08:26:05 +0200 | [diff] [blame] | 406 | /* 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 Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 413 | } |
| 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 |
| 421 | static __inline__ void pcs440ep_checksha1 (void) { do {} while (0);} |
| 422 | #endif |
| 423 | |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 424 | int misc_init_r (void) |
| 425 | { |
| 426 | uint pbcr; |
| 427 | int size_val = 0; |
| 428 | |
Mike Frysinger | 9c15010 | 2009-02-11 20:09:52 -0500 | [diff] [blame] | 429 | load_ethaddr(); |
| 430 | |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 431 | /* Re-do sizing to get full correct info */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 432 | mtdcr(EBC0_CFGADDR, PB0CR); |
| 433 | pbcr = mfdcr(EBC0_CFGDATA); |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 434 | 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 Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 461 | mtdcr(EBC0_CFGADDR, PB0CR); |
| 462 | mtdcr(EBC0_CFGDATA, pbcr); |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 463 | |
| 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-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 470 | -CONFIG_SYS_MONITOR_LEN, |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 471 | 0xffffffff, |
| 472 | &flash_info[1]); |
| 473 | |
| 474 | /* Env protection ON by default */ |
| 475 | (void)flash_protect(FLAG_PROTECT_SET, |
Jean-Christophe PLAGNIOL-VILLARD | 0e8d158 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 476 | CONFIG_ENV_ADDR_REDUND, |
| 477 | CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1, |
Stefan Roese | 4526c87 | 2006-06-06 10:59:12 +0200 | [diff] [blame] | 478 | &flash_info[1]); |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 479 | |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 480 | 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 Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | int checkboard(void) |
| 496 | { |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 497 | char buf[64]; |
| 498 | int i = getenv_f("serial#", buf, sizeof(buf)); |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 499 | |
| 500 | printf("Board: PCS440EP"); |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 501 | if (i > 0) { |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 502 | puts(", serial# "); |
Wolfgang Denk | f0c0b3a | 2011-05-04 10:32:28 +0000 | [diff] [blame] | 503 | puts(buf); |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 504 | } |
| 505 | putc('\n'); |
| 506 | |
| 507 | return (0); |
| 508 | } |
| 509 | |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 510 | void 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 Schocher | 9079024 | 2007-07-13 08:26:05 +0200 | [diff] [blame] | 516 | puts ("### SDRAM ERROR ### Please RESET the board ###\n"); |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 517 | for (;;) { |
| 518 | __led_toggle (4); |
| 519 | udelay (100000); |
| 520 | } |
| 521 | } |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 522 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 523 | phys_size_t initdram (int board_type) |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 524 | { |
| 525 | long dram_size = 0; |
| 526 | |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 527 | status_led_set (0, STATUS_LED_ON); |
| 528 | status_led_set (1, STATUS_LED_OFF); |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 529 | dram_size = spd_sdram(); |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 530 | status_led_set (0, STATUS_LED_OFF); |
| 531 | status_led_set (1, STATUS_LED_ON); |
| 532 | if (dram_size == 0) { |
| 533 | hang(); |
| 534 | } |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 535 | |
| 536 | return dram_size; |
| 537 | } |
| 538 | |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 539 | /************************************************************************* |
Stefan Roese | a4c8d13 | 2006-06-02 16:18:04 +0200 | [diff] [blame] | 540 | * hw_watchdog_reset |
| 541 | * |
| 542 | * This routine is called to reset (keep alive) the watchdog timer |
| 543 | * |
| 544 | ************************************************************************/ |
| 545 | #if defined(CONFIG_HW_WATCHDOG) |
| 546 | void hw_watchdog_reset(void) |
| 547 | { |
| 548 | |
| 549 | } |
| 550 | #endif |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 551 | |
| 552 | /************************************************************************* |
| 553 | * "led" Commando for the U-Boot shell |
| 554 | * |
| 555 | ************************************************************************/ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 556 | int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 557 | { |
Heiko Schocher | 96e1d75 | 2007-07-11 18:39:11 +0200 | [diff] [blame] | 558 | int rcode = 0, i; |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 559 | ulong pattern = 0; |
| 560 | |
Heiko Schocher | 96e1d75 | 2007-07-11 18:39:11 +0200 | [diff] [blame] | 561 | 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 Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 568 | status_led_blink (); |
| 569 | hang (); |
| 570 | return rcode; |
| 571 | } |
Heiko Schocher | 96e1d75 | 2007-07-11 18:39:11 +0200 | [diff] [blame] | 572 | if (pattern > 0x100) { |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 573 | status_led_blink (); |
| 574 | return rcode; |
| 575 | } |
| 576 | pattern &= 0x0f; |
Heiko Schocher | 96e1d75 | 2007-07-11 18:39:11 +0200 | [diff] [blame] | 577 | 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 Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 582 | return rcode; |
| 583 | } |
| 584 | |
| 585 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 586 | led, 2, 1, do_led, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 587 | "set the DIAG-LED", |
Heiko Schocher | 96e1d75 | 2007-07-11 18:39:11 +0200 | [diff] [blame] | 588 | "[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 Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 592 | " > 0x100 set the LED, who are on, to state blinking" |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 593 | ); |
| 594 | |
| 595 | #if defined(CONFIG_SHA1_CHECK_UB_IMG) |
| 596 | /************************************************************************* |
| 597 | * "sha1" Commando for the U-Boot shell |
| 598 | * |
| 599 | ************************************************************************/ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 600 | int do_sha1 (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 601 | { |
| 602 | int rcode = -1; |
| 603 | |
| 604 | if (argc < 2) { |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 605 | usage: |
| 606 | return cmd_usage(cmdtp); |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | if (argc >= 3) { |
| 610 | unsigned char *data; |
| 611 | unsigned char output[20]; |
| 612 | int len; |
| 613 | int i; |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 614 | |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 615 | 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 Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 641 | return rcode; |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 642 | } |
| 643 | return rcode; |
| 644 | } |
| 645 | |
| 646 | U_BOOT_CMD( |
Wolfgang Denk | 53677ef | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 647 | sha1, 4, 1, do_sha1, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 648 | "calculate the SHA1 Sum", |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 649 | "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 Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 651 | " -c check the U-Boot image in flash" |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 652 | ); |
| 653 | #endif |
| 654 | |
Heiko Schocher | f98984c | 2007-08-28 17:39:14 +0200 | [diff] [blame] | 655 | #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 Schocher | f98984c | 2007-08-28 17:39:14 +0200 | [diff] [blame] | 660 | void 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 | } |
| 667 | unsigned 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 Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 677 | #ifdef CONFIG_IDE_PREINIT |
| 678 | int 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 Denk | afaac86 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 689 | #if defined (CONFIG_CMD_IDE) && defined (CONFIG_IDE_RESET) |
Heiko Schocher | 566a494 | 2007-06-22 19:11:54 +0200 | [diff] [blame] | 690 | void 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 Denk | afaac86 | 2007-08-12 14:27:39 +0200 | [diff] [blame] | 700 | #endif /* defined (CONFIG_CMD_IDE) && defined (CONFIG_IDE_RESET) */ |
Pavel Herrmann | 21d2bf4 | 2012-10-07 05:56:13 +0000 | [diff] [blame] | 701 | |
| 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 | |
| 707 | void 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 | |
| 722 | void 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 | |
| 737 | void 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 |