pcs440ep.c 19 KB

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