misc.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 char console_buffer[CFG_CBSIZE];
  31. extern int l2_cache_enable (int l2control);
  32. extern int eepro100_write_eeprom (struct eth_device* dev, int location,
  33. int addr_len, unsigned short data);
  34. extern int read_eeprom (struct eth_device* dev, int location, int addr_len);
  35. /*----------------------------------------------------------------------------*/
  36. /*
  37. * read/write to nvram is only byte access
  38. */
  39. void *nvram_read(void *dest, const long src, size_t count)
  40. {
  41. uchar *d = (uchar *) dest;
  42. uchar *s = (uchar *) (CFG_ENV_MAP_ADRS + src);
  43. while (count--)
  44. *d++ = *s++;
  45. return dest;
  46. }
  47. void nvram_write(long dest, const void *src, size_t count)
  48. {
  49. uchar *d = (uchar *) (CFG_ENV_MAP_ADRS + dest);
  50. uchar *s = (uchar *) src;
  51. while (count--)
  52. *d++ = *s++;
  53. }
  54. /*----------------------------------------------------------------------------*/
  55. /*
  56. * handle sroms on ELPPC
  57. * fix ether address
  58. * set serial console as default
  59. */
  60. int misc_init_r (void)
  61. {
  62. revinfo eerev;
  63. u_char *ptr;
  64. u_int i, l, initSrom, copyNv;
  65. char buf[256];
  66. char hex[23] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0,
  67. 0, 0, 0, 0, 10, 11, 12, 13, 14, 15 };
  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, CFG_NV_SROM_COPY_ADDR, CFG_SROM_SIZE);
  85. if (strcmp (eerev.magic, "ELTEC") != 0)
  86. {
  87. /* srom is not initialized -> create a default revision info */
  88. for (i = 0, ptr = (u_char *)&eerev; i < sizeof(revinfo); 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. *(int*)&eerev.res[0] = 0;
  104. initSrom = 1; /* force dialog */
  105. copyNv = 1; /* copy to nvram */
  106. }
  107. if ((copyNv == 0) && (el_srom_checksum((u_char*)&eerev, CFG_SROM_SIZE) !=
  108. el_srom_checksum((u_char*)buf, CFG_SROM_SIZE)))
  109. {
  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. {
  116. switch ((char)toupper(console_buffer[0]))
  117. {
  118. case 'C':
  119. copyNv = 1;
  120. break;
  121. case 'R':
  122. copyNv = 1;
  123. initSrom = 1;
  124. break;
  125. }
  126. }
  127. }
  128. if (initSrom)
  129. {
  130. memcpy (buf, &eerev.revision[0][0], 14); /* save all revision info */
  131. printf ("Enter revision number (0-9): %c ", eerev.revision[0][0]);
  132. if (0 != readline (NULL))
  133. {
  134. eerev.revision[0][0] = (char)toupper(console_buffer[0]);
  135. memcpy (&eerev.revision[1][0], buf, 12); /* shift rest of rev info */
  136. }
  137. printf ("Enter revision character (A-Z): %c ", eerev.revision[0][1]);
  138. if (1 == readline (NULL))
  139. {
  140. eerev.revision[0][1] = (char)toupper(console_buffer[0]);
  141. }
  142. printf ("Enter board name (V-XXXX-XXXX): %s ", (char *)&eerev.board);
  143. if (11 == readline (NULL))
  144. {
  145. for (i=0; i<11; i++)
  146. eerev.board[i] = (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. {
  152. for (i=0; i<6; i++)
  153. eerev.serial[i] = console_buffer[i];
  154. eerev.serial[6] = '\0';
  155. }
  156. printf ("Enter ether node ID with leading zero (HEX): %02x%02x%02x%02x%02x%02x ",
  157. eerev.etheraddr[0], eerev.etheraddr[1],
  158. eerev.etheraddr[2], eerev.etheraddr[3],
  159. eerev.etheraddr[4], eerev.etheraddr[5]);
  160. if (12 == readline (NULL))
  161. {
  162. for (i=0; i<12; i+=2)
  163. eerev.etheraddr[i>>1] = (char)(16*hex[toupper(console_buffer[i])-'0'] +
  164. hex[toupper(console_buffer[i+1])-'0']);
  165. }
  166. l = strlen ((char *)&eerev.text);
  167. printf("Add to text section (max 64 chr): %s ", (char *)&eerev.text );
  168. if (0 != readline (NULL))
  169. {
  170. for (i = l; i<63; i++)
  171. eerev.text[i] = console_buffer[i-l];
  172. eerev.text[63] = '\0';
  173. }
  174. /* prepare network eeprom */
  175. memset (buf, 0, 128);
  176. buf[0] = eerev.etheraddr[1];
  177. buf[1] = eerev.etheraddr[0];
  178. buf[2] = eerev.etheraddr[3];
  179. buf[3] = eerev.etheraddr[2];
  180. buf[4] = eerev.etheraddr[5];
  181. buf[5] = eerev.etheraddr[4];
  182. *(unsigned short *)&buf[20] = 0x48B2;
  183. *(unsigned short *)&buf[22] = 0x0004;
  184. *(unsigned short *)&buf[24] = 0x1433;
  185. printf("\nSRom: Writing i82559 info ........ ");
  186. if (eepro100_srom_store ((unsigned short *)buf) == -1)
  187. printf("FAILED\n");
  188. else
  189. printf("OK\n");
  190. /* update CRC */
  191. eerev.crc = el_srom_checksum((u_char *)eerev.board, eerev.size);
  192. /* write new values */
  193. printf("\nSRom: Writing revision info ...... ");
  194. if (mpc107_srom_store((BLOCK_SIZE-sizeof(revinfo)), (u_char *)&eerev,
  195. sizeof(revinfo), SECOND_DEVICE, FIRST_BLOCK) == -1)
  196. printf("FAILED\n\n");
  197. else
  198. printf("OK\n\n");
  199. /* write new values as shadow image to nvram */
  200. nvram_write (CFG_NV_SROM_COPY_ADDR, (void *)&eerev, CFG_SROM_SIZE);
  201. } /*if (initSrom) */
  202. /* copy current values as shadow image to nvram */
  203. if (initSrom == 0 && copyNv == 1)
  204. nvram_write (CFG_NV_SROM_COPY_ADDR, (void *)&eerev, CFG_SROM_SIZE);
  205. /* update environment */
  206. sprintf (buf, "%02x:%02x:%02x:%02x:%02x:%02x",
  207. eerev.etheraddr[0], eerev.etheraddr[1],
  208. eerev.etheraddr[2], eerev.etheraddr[3],
  209. eerev.etheraddr[4], eerev.etheraddr[5]);
  210. setenv ("ethaddr", buf);
  211. /* set serial console as default */
  212. if ((ptr = getenv ("console")) == NULL)
  213. setenv ("console", "serial");
  214. /* print actual board identification */
  215. printf("Ident: %s Ser %s Rev %c%c\n",
  216. eerev.board, (char *)&eerev.serial,
  217. eerev.revision[0][0], eerev.revision[0][1]);
  218. return (0);
  219. }
  220. /*----------------------------------------------------------------------------*/