misc.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * (C) Copyright 2002 ELTEC Elektronik AG
  3. * Frank Gottschling <fgottschling@eltec.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. /* includes */
  24. #include <common.h>
  25. #include <linux/ctype.h>
  26. #include <pci.h>
  27. #include <net.h>
  28. #include "srom.h"
  29. /* imports */
  30. extern int l2_cache_enable (int l2control);
  31. extern int eepro100_write_eeprom (struct eth_device *dev, int location,
  32. int addr_len, unsigned short data);
  33. extern int read_eeprom (struct eth_device *dev, int location, int addr_len);
  34. /*----------------------------------------------------------------------------*/
  35. /*
  36. * read/write to nvram is only byte access
  37. */
  38. void *nvram_read (void *dest, const long src, size_t count)
  39. {
  40. uchar *d = (uchar *) dest;
  41. uchar *s = (uchar *) (CONFIG_ENV_MAP_ADRS + src);
  42. while (count--)
  43. *d++ = *s++;
  44. return dest;
  45. }
  46. void nvram_write (long dest, const void *src, size_t count)
  47. {
  48. uchar *d = (uchar *) (CONFIG_ENV_MAP_ADRS + dest);
  49. uchar *s = (uchar *) src;
  50. while (count--)
  51. *d++ = *s++;
  52. }
  53. /*----------------------------------------------------------------------------*/
  54. /*
  55. * handle sroms on ELPPC
  56. * fix ether address
  57. * set serial console as default
  58. */
  59. int misc_init_r (void)
  60. {
  61. revinfo eerev;
  62. u_char *ptr;
  63. u_int i, l, initSrom, copyNv;
  64. char buf[256];
  65. char hex[23] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0,
  66. 0, 0, 0, 0, 10, 11, 12, 13, 14, 15
  67. };
  68. /* Clock setting for MPC107 i2c */
  69. mpc107_i2c_init (MPC107_EUMB_ADDR, 0x2b);
  70. /* Reset the EPIC */
  71. out32r (MPC107_EUMB_GCR, 0xa0000000);
  72. while (in32r (MPC107_EUMB_GCR) & 0x80000000); /* Wait for reset to complete */
  73. out32r (MPC107_EUMB_GCR, 0x20000000); /* Put into into mixed mode */
  74. while (in32r (MPC107_EUMB_IACKR) != 0xff); /* Clear all pending interrupts */
  75. /*
  76. * Check/Remake revision info
  77. */
  78. initSrom = 0;
  79. copyNv = 0;
  80. /* read out current revision srom contens */
  81. mpc107_srom_load (0x0000, (u_char *) & eerev, sizeof (revinfo),
  82. SECOND_DEVICE, FIRST_BLOCK);
  83. /* read out current nvram shadow image */
  84. nvram_read (buf, CONFIG_SYS_NV_SROM_COPY_ADDR, CONFIG_SYS_SROM_SIZE);
  85. if (strcmp (eerev.magic, "ELTEC") != 0) {
  86. /* srom is not initialized -> create a default revision info */
  87. for (i = 0, ptr = (u_char *) & eerev; i < sizeof (revinfo);
  88. i++)
  89. *ptr++ = 0x00;
  90. strcpy (eerev.magic, "ELTEC");
  91. eerev.revrev[0] = 1;
  92. eerev.revrev[1] = 0;
  93. eerev.size = 0x00E0;
  94. eerev.category[0] = 0x01;
  95. /* node id from dead e128 as default */
  96. eerev.etheraddr[0] = 0x00;
  97. eerev.etheraddr[1] = 0x00;
  98. eerev.etheraddr[2] = 0x5B;
  99. eerev.etheraddr[3] = 0x00;
  100. eerev.etheraddr[4] = 0x2E;
  101. eerev.etheraddr[5] = 0x4D;
  102. /* cache config word for ELPPC */
  103. memset(&eerev.res[0], 0, 4);
  104. initSrom = 1; /* force dialog */
  105. copyNv = 1; /* copy to nvram */
  106. }
  107. if ((copyNv == 0)
  108. && (el_srom_checksum ((u_char *) & eerev, CONFIG_SYS_SROM_SIZE) !=
  109. el_srom_checksum ((u_char *) buf, CONFIG_SYS_SROM_SIZE))) {
  110. printf ("Invalid revision info copy in nvram !\n");
  111. printf ("Press key:\n <c> to copy current revision info to nvram.\n");
  112. printf (" <r> to reenter revision info.\n");
  113. printf ("=> ");
  114. if (0 != readline (NULL)) {
  115. switch ((char) toupper (console_buffer[0])) {
  116. case 'C':
  117. copyNv = 1;
  118. break;
  119. case 'R':
  120. copyNv = 1;
  121. initSrom = 1;
  122. break;
  123. }
  124. }
  125. }
  126. if (initSrom) {
  127. memcpy (buf, &eerev.revision[0][0], 14); /* save all revision info */
  128. printf ("Enter revision number (0-9): %c ",
  129. eerev.revision[0][0]);
  130. if (0 != readline (NULL)) {
  131. eerev.revision[0][0] =
  132. (char) toupper (console_buffer[0]);
  133. memcpy (&eerev.revision[1][0], buf, 12); /* shift rest of rev info */
  134. }
  135. printf ("Enter revision character (A-Z): %c ",
  136. eerev.revision[0][1]);
  137. if (1 == readline (NULL)) {
  138. eerev.revision[0][1] =
  139. (char) toupper (console_buffer[0]);
  140. }
  141. printf ("Enter board name (V-XXXX-XXXX): %s ",
  142. (char *) &eerev.board);
  143. if (11 == readline (NULL)) {
  144. for (i = 0; i < 11; i++)
  145. eerev.board[i] =
  146. (char) toupper (console_buffer[i]);
  147. eerev.board[11] = '\0';
  148. }
  149. printf ("Enter serial number: %s ", (char *) &eerev.serial);
  150. if (6 == readline (NULL)) {
  151. for (i = 0; i < 6; i++)
  152. eerev.serial[i] = console_buffer[i];
  153. eerev.serial[6] = '\0';
  154. }
  155. printf ("Enter ether node ID with leading zero (HEX): %02x%02x%02x%02x%02x%02x ", eerev.etheraddr[0], eerev.etheraddr[1], eerev.etheraddr[2], eerev.etheraddr[3], eerev.etheraddr[4], eerev.etheraddr[5]);
  156. if (12 == readline (NULL)) {
  157. for (i = 0; i < 12; i += 2)
  158. eerev.etheraddr[i >> 1] =
  159. (char) (16 *
  160. hex[toupper
  161. (console_buffer[i]) -
  162. '0'] +
  163. hex[toupper
  164. (console_buffer[i + 1]) -
  165. '0']);
  166. }
  167. l = strlen ((char *) &eerev.text);
  168. printf ("Add to text section (max 64 chr): %s ",
  169. (char *) &eerev.text);
  170. if (0 != readline (NULL)) {
  171. for (i = l; i < 63; i++)
  172. eerev.text[i] = console_buffer[i - l];
  173. eerev.text[63] = '\0';
  174. }
  175. /* prepare network eeprom */
  176. memset (buf, 0, 128);
  177. buf[0] = eerev.etheraddr[1];
  178. buf[1] = eerev.etheraddr[0];
  179. buf[2] = eerev.etheraddr[3];
  180. buf[3] = eerev.etheraddr[2];
  181. buf[4] = eerev.etheraddr[5];
  182. buf[5] = eerev.etheraddr[4];
  183. *(unsigned short *) &buf[20] = 0x48B2;
  184. *(unsigned short *) &buf[22] = 0x0004;
  185. *(unsigned short *) &buf[24] = 0x1433;
  186. printf ("\nSRom: Writing i82559 info ........ ");
  187. if (eepro100_srom_store ((unsigned short *) buf) == -1)
  188. printf ("FAILED\n");
  189. else
  190. printf ("OK\n");
  191. /* update CRC */
  192. eerev.crc =
  193. el_srom_checksum ((u_char *) eerev.board, eerev.size);
  194. /* write new values */
  195. printf ("\nSRom: Writing revision info ...... ");
  196. if (mpc107_srom_store
  197. ((BLOCK_SIZE - sizeof (revinfo)), (u_char *) & eerev,
  198. sizeof (revinfo), SECOND_DEVICE, FIRST_BLOCK) == -1)
  199. printf ("FAILED\n\n");
  200. else
  201. printf ("OK\n\n");
  202. /* write new values as shadow image to nvram */
  203. nvram_write (CONFIG_SYS_NV_SROM_COPY_ADDR, (void *) &eerev,
  204. CONFIG_SYS_SROM_SIZE);
  205. }
  206. /*if (initSrom) */
  207. /* copy current values as shadow image to nvram */
  208. if (initSrom == 0 && copyNv == 1)
  209. nvram_write (CONFIG_SYS_NV_SROM_COPY_ADDR, (void *) &eerev,
  210. CONFIG_SYS_SROM_SIZE);
  211. /* update environment */
  212. sprintf (buf, "%02x:%02x:%02x:%02x:%02x:%02x",
  213. eerev.etheraddr[0], eerev.etheraddr[1],
  214. eerev.etheraddr[2], eerev.etheraddr[3],
  215. eerev.etheraddr[4], eerev.etheraddr[5]);
  216. setenv ("ethaddr", buf);
  217. /* print actual board identification */
  218. printf ("Ident: %s Ser %s Rev %c%c\n",
  219. eerev.board, (char *) &eerev.serial,
  220. eerev.revision[0][0], eerev.revision[0][1]);
  221. return (0);
  222. }
  223. /*----------------------------------------------------------------------------*/