pcs440ep.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /*
  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. #include <common.h>
  24. #include <asm/ppc4xx.h>
  25. #include <malloc.h>
  26. #include <command.h>
  27. #include <crc.h>
  28. #include <asm/processor.h>
  29. #include <spd_sdram.h>
  30. #include <status_led.h>
  31. #include <sha1.h>
  32. #include <asm/io.h>
  33. #include <net.h>
  34. DECLARE_GLOBAL_DATA_PTR;
  35. extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
  36. unsigned char sha1_checksum[SHA1_SUM_LEN];
  37. /* swap 4 Bits (Bit0 = Bit3, Bit1 = Bit2, Bit2 = Bit1 and Bit3 = Bit0) */
  38. unsigned char swapbits[16] = {0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
  39. 0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf};
  40. static void set_leds (int val)
  41. {
  42. out32(GPIO0_OR, (in32 (GPIO0_OR) & ~0x78000000) | (val << 27));
  43. }
  44. #define GET_LEDS ((in32 (GPIO0_OR) & 0x78000000) >> 27)
  45. void __led_init (led_id_t mask, int state)
  46. {
  47. int val = GET_LEDS;
  48. if (state == STATUS_LED_ON)
  49. val |= mask;
  50. else
  51. val &= ~mask;
  52. set_leds (val);
  53. }
  54. void __led_set (led_id_t mask, int state)
  55. {
  56. int val = GET_LEDS;
  57. if (state == STATUS_LED_ON)
  58. val |= mask;
  59. else if (state == STATUS_LED_OFF)
  60. val &= ~mask;
  61. set_leds (val);
  62. }
  63. void __led_toggle (led_id_t mask)
  64. {
  65. int val = GET_LEDS;
  66. val ^= mask;
  67. set_leds (val);
  68. }
  69. static void status_led_blink (void)
  70. {
  71. int i;
  72. int val = GET_LEDS;
  73. /* set all LED which are on, to state BLINKING */
  74. for (i = 0; i < 4; i++) {
  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;
  78. }
  79. }
  80. #if defined(CONFIG_SHOW_BOOT_PROGRESS)
  81. void show_boot_progress (int val)
  82. {
  83. /* find all valid Codes for val in README */
  84. if (val == -30) return;
  85. if (val < 0) {
  86. /* smthing goes wrong */
  87. status_led_blink ();
  88. return;
  89. }
  90. switch (val) {
  91. case 1:
  92. /* validating Image */
  93. status_led_set (0, STATUS_LED_OFF);
  94. status_led_set (1, STATUS_LED_ON);
  95. status_led_set (2, STATUS_LED_ON);
  96. break;
  97. case 15:
  98. /* booting */
  99. status_led_set (0, STATUS_LED_ON);
  100. status_led_set (1, STATUS_LED_ON);
  101. status_led_set (2, STATUS_LED_ON);
  102. break;
  103. #if 0
  104. case 64:
  105. /* starting Ethernet configuration */
  106. status_led_set (0, STATUS_LED_OFF);
  107. status_led_set (1, STATUS_LED_OFF);
  108. status_led_set (2, STATUS_LED_ON);
  109. break;
  110. #endif
  111. case 80:
  112. /* loading Image */
  113. status_led_set (0, STATUS_LED_ON);
  114. status_led_set (1, STATUS_LED_OFF);
  115. status_led_set (2, STATUS_LED_ON);
  116. break;
  117. }
  118. }
  119. #endif
  120. int board_early_init_f(void)
  121. {
  122. register uint reg;
  123. set_leds(0); /* display boot info counter */
  124. /*--------------------------------------------------------------------
  125. * Setup the external bus controller/chip selects
  126. *-------------------------------------------------------------------*/
  127. mtdcr(EBC0_CFGADDR, EBC0_CFG);
  128. reg = mfdcr(EBC0_CFGDATA);
  129. mtdcr(EBC0_CFGDATA, reg | 0x04000000); /* Set ATC */
  130. /*--------------------------------------------------------------------
  131. * GPIO's are alreay setup in arch/powerpc/cpu/ppc4xx/cpu_init.c
  132. * via define from board config file.
  133. *-------------------------------------------------------------------*/
  134. /*--------------------------------------------------------------------
  135. * Setup the interrupt controller polarities, triggers, etc.
  136. *-------------------------------------------------------------------*/
  137. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  138. mtdcr(UIC0ER, 0x00000000); /* disable all */
  139. mtdcr(UIC0CR, 0x00000001); /* UIC1 crit is critical */
  140. mtdcr(UIC0PR, 0xfffffe1f); /* per ref-board manual */
  141. mtdcr(UIC0TR, 0x01c00000); /* per ref-board manual */
  142. mtdcr(UIC0VR, 0x00000001); /* int31 highest, base=0x000 */
  143. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  144. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  145. mtdcr(UIC1ER, 0x00000000); /* disable all */
  146. mtdcr(UIC1CR, 0x00000000); /* all non-critical */
  147. mtdcr(UIC1PR, 0xffffe0ff); /* per ref-board manual */
  148. mtdcr(UIC1TR, 0x00ffc000); /* per ref-board manual */
  149. mtdcr(UIC1VR, 0x00000001); /* int31 highest, base=0x000 */
  150. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  151. /*--------------------------------------------------------------------
  152. * Setup other serial configuration
  153. *-------------------------------------------------------------------*/
  154. mfsdr(SDR0_PCI0, reg);
  155. mtsdr(SDR0_PCI0, 0x80000000 | reg); /* PCI arbiter enabled */
  156. mtsdr(SDR0_PFC0, 0x00000000); /* Pin function: enable GPIO49-63 */
  157. mtsdr(SDR0_PFC1, 0x00048000); /* Pin function: UART0 has 4 pins, select IRQ5 */
  158. return 0;
  159. }
  160. #define EEPROM_LEN 256
  161. static void load_ethaddr(void)
  162. {
  163. int ok_ethaddr, ok_eth1addr;
  164. int ret;
  165. uchar buf[EEPROM_LEN];
  166. char *use_eeprom;
  167. u16 checksumcrc16 = 0;
  168. /* If the env is sane, then nothing for us to do */
  169. ok_ethaddr = eth_getenv_enetaddr("ethaddr", buf);
  170. ok_eth1addr = eth_getenv_enetaddr("eth1addr", buf);
  171. if (ok_ethaddr && ok_eth1addr)
  172. return;
  173. /* read the MACs from EEprom */
  174. status_led_set (0, STATUS_LED_ON);
  175. status_led_set (1, STATUS_LED_ON);
  176. ret = eeprom_read (CONFIG_SYS_I2C_EEPROM_ADDR, 0, buf, EEPROM_LEN);
  177. if (ret == 0) {
  178. checksumcrc16 = cyg_crc16 (buf, EEPROM_LEN - 2);
  179. /* check, if the EEprom is programmed:
  180. * - The Prefix(Byte 0,1,2) is equal to "ATR"
  181. * - The checksum, stored in the last 2 Bytes, is correct
  182. */
  183. if ((strncmp ((char *)buf,"ATR",3) != 0) ||
  184. ((checksumcrc16 >> 8) != buf[EEPROM_LEN - 2]) ||
  185. ((checksumcrc16 & 0xff) != buf[EEPROM_LEN - 1])) {
  186. /* EEprom is not programmed */
  187. printf("%s: EEPROM Checksum not OK\n", __FUNCTION__);
  188. } else {
  189. /* get the MACs */
  190. if (!ok_ethaddr)
  191. eth_setenv_enetaddr("ethaddr", &buf[3]);
  192. if (!ok_eth1addr)
  193. eth_setenv_enetaddr("eth1addr", &buf[9]);
  194. return;
  195. }
  196. }
  197. /* some error reading the EEprom */
  198. if ((use_eeprom = getenv ("use_eeprom_ethaddr")) == NULL) {
  199. /* dont use bootcmd */
  200. setenv("bootdelay", "-1");
  201. return;
  202. }
  203. /* == default ? use standard */
  204. if (strncmp (use_eeprom, "default", 7) == 0) {
  205. return;
  206. }
  207. /* Env doesnt exist -> hang */
  208. status_led_blink ();
  209. /* here we do this "handy" because we have no interrupts
  210. at this time */
  211. puts ("### EEPROM ERROR ### Please RESET the board ###\n");
  212. for (;;) {
  213. __led_toggle (12);
  214. udelay (100000);
  215. }
  216. return;
  217. }
  218. #ifdef CONFIG_PREBOOT
  219. static uchar kbd_magic_prefix[] = "key_magic";
  220. static uchar kbd_command_prefix[] = "key_cmd";
  221. struct kbd_data_t {
  222. char s1;
  223. char s2;
  224. };
  225. struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
  226. {
  227. char *val;
  228. unsigned long tmp;
  229. /* use the DIPs for some bootoptions */
  230. val = getenv (ENV_NAME_DIP);
  231. tmp = simple_strtoul (val, NULL, 16);
  232. kbd_data->s2 = (tmp & 0x0f);
  233. kbd_data->s1 = (tmp & 0xf0) >> 4;
  234. return kbd_data;
  235. }
  236. static int compare_magic (const struct kbd_data_t *kbd_data, char *str)
  237. {
  238. char s1 = str[0];
  239. if (s1 >= '0' && s1 <= '9')
  240. s1 -= '0';
  241. else if (s1 >= 'a' && s1 <= 'f')
  242. s1 = s1 - 'a' + 10;
  243. else if (s1 >= 'A' && s1 <= 'F')
  244. s1 = s1 - 'A' + 10;
  245. else
  246. return -1;
  247. if (s1 != kbd_data->s1) return -1;
  248. s1 = str[1];
  249. if (s1 >= '0' && s1 <= '9')
  250. s1 -= '0';
  251. else if (s1 >= 'a' && s1 <= 'f')
  252. s1 = s1 - 'a' + 10;
  253. else if (s1 >= 'A' && s1 <= 'F')
  254. s1 = s1 - 'A' + 10;
  255. else
  256. return -1;
  257. if (s1 != kbd_data->s2) return -1;
  258. return 0;
  259. }
  260. static char *key_match (const struct kbd_data_t *kbd_data)
  261. {
  262. char magic[sizeof (kbd_magic_prefix) + 1];
  263. char *suffix;
  264. char *kbd_magic_keys;
  265. /*
  266. * The following string defines the characters that can be appended
  267. * to "key_magic" to form the names of environment variables that
  268. * hold "magic" key codes, i. e. such key codes that can cause
  269. * pre-boot actions. If the string is empty (""), then only
  270. * "key_magic" is checked (old behaviour); the string "125" causes
  271. * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
  272. */
  273. if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
  274. kbd_magic_keys = "";
  275. /* loop over all magic keys;
  276. * use '\0' suffix in case of empty string
  277. */
  278. for (suffix = kbd_magic_keys; *suffix ||
  279. suffix == kbd_magic_keys; ++suffix) {
  280. sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
  281. if (compare_magic (kbd_data, getenv (magic)) == 0) {
  282. char cmd_name[sizeof (kbd_command_prefix) + 1];
  283. char *cmd;
  284. sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
  285. cmd = getenv (cmd_name);
  286. return (cmd);
  287. }
  288. }
  289. return (NULL);
  290. }
  291. #endif /* CONFIG_PREBOOT */
  292. static int pcs440ep_readinputs (void)
  293. {
  294. int i;
  295. char value[20];
  296. /* read the inputs and set the Envvars */
  297. /* Revision Level Bit 26 - 29 */
  298. i = ((in32 (GPIO0_IR) & 0x0000003c) >> 2);
  299. i = swapbits[i];
  300. sprintf (value, "%02x", i);
  301. setenv (ENV_NAME_REVLEV, value);
  302. /* Solder Switch Bit 30 - 33 */
  303. i = (in32 (GPIO0_IR) & 0x00000003) << 2;
  304. i += (in32 (GPIO1_IR) & 0xc0000000) >> 30;
  305. i = swapbits[i];
  306. sprintf (value, "%02x", i);
  307. setenv (ENV_NAME_SOLDER, value);
  308. /* DIP Switch Bit 49 - 56 */
  309. i = ((in32 (GPIO1_IR) & 0x00007f80) >> 7);
  310. i = (swapbits[i & 0x0f] << 4) + swapbits[(i & 0xf0) >> 4];
  311. sprintf (value, "%02x", i);
  312. setenv (ENV_NAME_DIP, value);
  313. return 0;
  314. }
  315. #if defined(CONFIG_SHA1_CHECK_UB_IMG)
  316. /*************************************************************************
  317. * calculate a SHA1 sum for the U-Boot image in Flash.
  318. *
  319. ************************************************************************/
  320. static int pcs440ep_sha1 (int docheck)
  321. {
  322. unsigned char *data;
  323. unsigned char *ptroff;
  324. unsigned char output[20];
  325. unsigned char org[20];
  326. int i, len = CONFIG_SHA1_LEN;
  327. memcpy ((char *)CONFIG_SYS_LOAD_ADDR, (char *)CONFIG_SHA1_START, len);
  328. data = (unsigned char *)CONFIG_SYS_LOAD_ADDR;
  329. ptroff = &data[len + SHA1_SUM_POS];
  330. for (i = 0; i < SHA1_SUM_LEN; i++) {
  331. org[i] = ptroff[i];
  332. ptroff[i] = 0;
  333. }
  334. sha1_csum ((unsigned char *) data, len, (unsigned char *)output);
  335. if (docheck == 2) {
  336. for (i = 0; i < 20 ; i++) {
  337. printf("%02X ", output[i]);
  338. }
  339. printf("\n");
  340. }
  341. if (docheck == 1) {
  342. for (i = 0; i < 20 ; i++) {
  343. if (org[i] != output[i]) return 1;
  344. }
  345. }
  346. return 0;
  347. }
  348. /*************************************************************************
  349. * do some checks after the SHA1 checksum from the U-Boot Image was
  350. * calculated.
  351. *
  352. ************************************************************************/
  353. static void pcs440ep_checksha1 (void)
  354. {
  355. int ret;
  356. char *cs_test;
  357. status_led_set (0, STATUS_LED_OFF);
  358. status_led_set (1, STATUS_LED_OFF);
  359. status_led_set (2, STATUS_LED_ON);
  360. ret = pcs440ep_sha1 (1);
  361. if (ret == 0) return;
  362. if ((cs_test = getenv ("cs_test")) == NULL) {
  363. /* Env doesnt exist -> hang */
  364. status_led_blink ();
  365. /* here we do this "handy" because we have no interrupts
  366. at this time */
  367. puts ("### SHA1 ERROR ### Please RESET the board ###\n");
  368. for (;;) {
  369. __led_toggle (2);
  370. udelay (100000);
  371. }
  372. }
  373. if (strncmp (cs_test, "off", 3) == 0) {
  374. printf ("SHA1 U-Boot sum NOT ok!\n");
  375. setenv ("bootdelay", "-1");
  376. }
  377. }
  378. #else
  379. static __inline__ void pcs440ep_checksha1 (void) { do {} while (0);}
  380. #endif
  381. int misc_init_r (void)
  382. {
  383. uint pbcr;
  384. int size_val = 0;
  385. load_ethaddr();
  386. /* Re-do sizing to get full correct info */
  387. mtdcr(EBC0_CFGADDR, PB0CR);
  388. pbcr = mfdcr(EBC0_CFGDATA);
  389. switch (gd->bd->bi_flashsize) {
  390. case 1 << 20:
  391. size_val = 0;
  392. break;
  393. case 2 << 20:
  394. size_val = 1;
  395. break;
  396. case 4 << 20:
  397. size_val = 2;
  398. break;
  399. case 8 << 20:
  400. size_val = 3;
  401. break;
  402. case 16 << 20:
  403. size_val = 4;
  404. break;
  405. case 32 << 20:
  406. size_val = 5;
  407. break;
  408. case 64 << 20:
  409. size_val = 6;
  410. break;
  411. case 128 << 20:
  412. size_val = 7;
  413. break;
  414. }
  415. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  416. mtdcr(EBC0_CFGADDR, PB0CR);
  417. mtdcr(EBC0_CFGDATA, pbcr);
  418. /* adjust flash start and offset */
  419. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  420. gd->bd->bi_flashoffset = 0;
  421. /* Monitor protection ON by default */
  422. (void)flash_protect(FLAG_PROTECT_SET,
  423. -CONFIG_SYS_MONITOR_LEN,
  424. 0xffffffff,
  425. &flash_info[1]);
  426. /* Env protection ON by default */
  427. (void)flash_protect(FLAG_PROTECT_SET,
  428. CONFIG_ENV_ADDR_REDUND,
  429. CONFIG_ENV_ADDR_REDUND + 2*CONFIG_ENV_SECT_SIZE - 1,
  430. &flash_info[1]);
  431. pcs440ep_readinputs ();
  432. pcs440ep_checksha1 ();
  433. #ifdef CONFIG_PREBOOT
  434. {
  435. struct kbd_data_t kbd_data;
  436. /* Decode keys */
  437. char *str = strdup (key_match (get_keys (&kbd_data)));
  438. /* Set or delete definition */
  439. setenv ("preboot", str);
  440. free (str);
  441. }
  442. #endif /* CONFIG_PREBOOT */
  443. return 0;
  444. }
  445. int checkboard(void)
  446. {
  447. char *s = getenv("serial#");
  448. printf("Board: PCS440EP");
  449. if (s != NULL) {
  450. puts(", serial# ");
  451. puts(s);
  452. }
  453. putc('\n');
  454. return (0);
  455. }
  456. void spd_ddr_init_hang (void)
  457. {
  458. status_led_set (0, STATUS_LED_OFF);
  459. status_led_set (1, STATUS_LED_ON);
  460. /* we cannot use hang() because we are still running from
  461. Flash, and so the status_led driver is not initialized */
  462. puts ("### SDRAM ERROR ### Please RESET the board ###\n");
  463. for (;;) {
  464. __led_toggle (4);
  465. udelay (100000);
  466. }
  467. }
  468. phys_size_t initdram (int board_type)
  469. {
  470. long dram_size = 0;
  471. status_led_set (0, STATUS_LED_ON);
  472. status_led_set (1, STATUS_LED_OFF);
  473. dram_size = spd_sdram();
  474. status_led_set (0, STATUS_LED_OFF);
  475. status_led_set (1, STATUS_LED_ON);
  476. if (dram_size == 0) {
  477. hang();
  478. }
  479. return dram_size;
  480. }
  481. /*************************************************************************
  482. * hw_watchdog_reset
  483. *
  484. * This routine is called to reset (keep alive) the watchdog timer
  485. *
  486. ************************************************************************/
  487. #if defined(CONFIG_HW_WATCHDOG)
  488. void hw_watchdog_reset(void)
  489. {
  490. }
  491. #endif
  492. /*************************************************************************
  493. * "led" Commando for the U-Boot shell
  494. *
  495. ************************************************************************/
  496. int do_led (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  497. {
  498. int rcode = 0, i;
  499. ulong pattern = 0;
  500. pattern = simple_strtoul (argv[1], NULL, 16);
  501. if (pattern > 0x400) {
  502. int val = GET_LEDS;
  503. printf ("led: %x\n", val);
  504. return rcode;
  505. }
  506. if (pattern > 0x200) {
  507. status_led_blink ();
  508. hang ();
  509. return rcode;
  510. }
  511. if (pattern > 0x100) {
  512. status_led_blink ();
  513. return rcode;
  514. }
  515. pattern &= 0x0f;
  516. for (i = 0; i < 4; i++) {
  517. if (pattern & 0x01) status_led_set (i, STATUS_LED_ON);
  518. else status_led_set (i, STATUS_LED_OFF);
  519. pattern = pattern >> 1;
  520. }
  521. return rcode;
  522. }
  523. U_BOOT_CMD(
  524. led, 2, 1, do_led,
  525. "set the DIAG-LED",
  526. "[bitmask] 0x01 = DIAG 1 on\n"
  527. " 0x02 = DIAG 2 on\n"
  528. " 0x04 = DIAG 3 on\n"
  529. " 0x08 = DIAG 4 on\n"
  530. " > 0x100 set the LED, who are on, to state blinking"
  531. );
  532. #if defined(CONFIG_SHA1_CHECK_UB_IMG)
  533. /*************************************************************************
  534. * "sha1" Commando for the U-Boot shell
  535. *
  536. ************************************************************************/
  537. int do_sha1 (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  538. {
  539. int rcode = -1;
  540. if (argc < 2) {
  541. usage:
  542. return cmd_usage(cmdtp);
  543. }
  544. if (argc >= 3) {
  545. unsigned char *data;
  546. unsigned char output[20];
  547. int len;
  548. int i;
  549. data = (unsigned char *)simple_strtoul (argv[1], NULL, 16);
  550. len = simple_strtoul (argv[2], NULL, 16);
  551. sha1_csum (data, len, (unsigned char *)output);
  552. printf ("U-Boot sum:\n");
  553. for (i = 0; i < 20 ; i++) {
  554. printf ("%02X ", output[i]);
  555. }
  556. printf ("\n");
  557. if (argc == 4) {
  558. data = (unsigned char *)simple_strtoul (argv[3], NULL, 16);
  559. memcpy (data, output, 20);
  560. }
  561. return 0;
  562. }
  563. if (argc == 2) {
  564. char *ptr = argv[1];
  565. if (*ptr != '-') goto usage;
  566. ptr++;
  567. if ((*ptr == 'c') || (*ptr == 'C')) {
  568. rcode = pcs440ep_sha1 (1);
  569. printf ("SHA1 U-Boot sum %sok!\n", (rcode != 0) ? "not " : "");
  570. } else if ((*ptr == 'p') || (*ptr == 'P')) {
  571. rcode = pcs440ep_sha1 (2);
  572. } else {
  573. rcode = pcs440ep_sha1 (0);
  574. }
  575. return rcode;
  576. }
  577. return rcode;
  578. }
  579. U_BOOT_CMD(
  580. sha1, 4, 1, do_sha1,
  581. "calculate the SHA1 Sum",
  582. "address len [addr] calculate the SHA1 sum [save at addr]\n"
  583. " -p calculate the SHA1 sum from the U-Boot image in flash and print\n"
  584. " -c check the U-Boot image in flash"
  585. );
  586. #endif
  587. #if defined (CONFIG_CMD_IDE)
  588. /* These addresses need to be shifted one place to the left
  589. * ( bus per_addr 20 -30 is connectsd on CF bus A10-A0)
  590. * These values are shifted
  591. */
  592. extern ulong *ide_bus_offset;
  593. void inline ide_outb(int dev, int port, unsigned char val)
  594. {
  595. debug ("ide_outb (dev= %d, port= 0x%x, val= 0x%02x) : @ 0x%08lx\n",
  596. dev, port, val, (ATA_CURR_BASE(dev)+port));
  597. out_be16((u16 *)(ATA_CURR_BASE(dev)+(port << 1)), val);
  598. }
  599. unsigned char inline ide_inb(int dev, int port)
  600. {
  601. uchar val;
  602. val = in_be16((u16 *)(ATA_CURR_BASE(dev)+(port << 1)));
  603. debug ("ide_inb (dev= %d, port= 0x%x) : @ 0x%08lx -> 0x%02x\n",
  604. dev, port, (ATA_CURR_BASE(dev)+port), val);
  605. return (val);
  606. }
  607. #endif
  608. #ifdef CONFIG_IDE_PREINIT
  609. int ide_preinit (void)
  610. {
  611. /* Set True IDE Mode */
  612. out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00100000));
  613. out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
  614. out32 (GPIO1_OR, (in32 (GPIO1_OR) & ~0x00008040));
  615. udelay (100000);
  616. return 0;
  617. }
  618. #endif
  619. #if defined (CONFIG_CMD_IDE) && defined (CONFIG_IDE_RESET)
  620. void ide_set_reset (int idereset)
  621. {
  622. debug ("ide_reset(%d)\n", idereset);
  623. if (idereset == 0) {
  624. out32 (GPIO0_OR, (in32 (GPIO0_OR) | 0x00200000));
  625. } else {
  626. out32 (GPIO0_OR, (in32 (GPIO0_OR) & ~0x00200000));
  627. }
  628. udelay (10000);
  629. }
  630. #endif /* defined (CONFIG_CMD_IDE) && defined (CONFIG_IDE_RESET) */