nm_bsp.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. *(C) Copyright 2005-2008 Netstal Maschinen AG
  3. * Niklaus Giger (Niklaus.Giger@netstal.com)
  4. *
  5. * This source code is free software; you can redistribute it
  6. * and/or modify it in source code form under the terms of the GNU
  7. * General Public License as published by the Free Software
  8. * Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  19. */
  20. #include <common.h>
  21. #include <command.h>
  22. #include <net.h>
  23. #include "nm.h"
  24. DECLARE_GLOBAL_DATA_PTR;
  25. #define DEFAULT_ETH_ADDR "ethaddr"
  26. typedef struct {u8 id; char *name;} generation_info;
  27. generation_info generations[6] = {
  28. {HW_GENERATION_HCU3, "HCU3"},
  29. {HW_GENERATION_HCU4, "HCU4"},
  30. {HW_GENERATION_HCU5, "HCU5"},
  31. {HW_GENERATION_MCU, "MCU"},
  32. {HW_GENERATION_MCU20, "MCU20"},
  33. {HW_GENERATION_MCU25, "MCU25"},
  34. };
  35. void nm_show_print(int generation, int index, int hw_capabilities)
  36. {
  37. int j;
  38. char *generationName=0;
  39. /* reset ANSI terminal color mode */
  40. printf("\x1B""[0m""Netstal Maschinen AG: ");
  41. for (j=0; j < (sizeof(generations)/sizeof(generations[0])); j++) {
  42. if (generations[j].id == generation) {
  43. generationName = generations[j].name;
  44. break;
  45. }
  46. }
  47. printf("%s: index %d HW 0x%x\n", generationName, index, hw_capabilities);
  48. for (j = 0;j < 6; j++) {
  49. hcu_led_set(1 << j);
  50. udelay(200 * 1000);
  51. }
  52. }
  53. void set_params_for_sw_install(int install_requested, char *board_name )
  54. {
  55. if (install_requested) {
  56. char string[128];
  57. printf("\n\n%s SW-Installation: %d patching boot parameters\n",
  58. board_name, install_requested);
  59. setenv("bootdelay", "0");
  60. setenv("loadaddr", "0x01000000");
  61. setenv("serverip", "172.25.1.1");
  62. setenv("bootcmd", "run install");
  63. sprintf(string, "tftp ${loadaddr} admin/sw_on_hd; "
  64. "tftp ${loadaddr} installer/%s_sw_inst; "
  65. "run boot_sw_inst", board_name);
  66. setenv("install", string);
  67. sprintf(string, "setenv bootargs emac(0,0)c:%s/%s_sw_inst "
  68. "e=${ipaddr} h=${serverip} f=0x1000; "
  69. "bootvx ${loadaddr}%c",
  70. board_name, board_name, 0);
  71. setenv("boot_sw_inst", string);
  72. }
  73. }
  74. void common_misc_init_r(void)
  75. {
  76. char *s = getenv(DEFAULT_ETH_ADDR);
  77. char *e;
  78. int i;
  79. u32 serial = get_serial_number();
  80. IPaddr_t ipaddr;
  81. char *ipstring;
  82. for (i = 0; i < 6; ++i) {
  83. gd->bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
  84. if (s)
  85. s = (*e) ? e + 1 : e;
  86. }
  87. if (gd->bd->bi_enetaddr[3] == 0 &&
  88. gd->bd->bi_enetaddr[4] == 0 &&
  89. gd->bd->bi_enetaddr[5] == 0) {
  90. char ethaddr[22];
  91. /* Must be in sync with CONFIG_ETHADDR */
  92. gd->bd->bi_enetaddr[0] = 0x00;
  93. gd->bd->bi_enetaddr[1] = 0x60;
  94. gd->bd->bi_enetaddr[2] = 0x13;
  95. gd->bd->bi_enetaddr[3] = (serial >> 16) & 0xff;
  96. gd->bd->bi_enetaddr[4] = (serial >> 8) & 0xff;
  97. gd->bd->bi_enetaddr[5] = hcu_get_slot();
  98. sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X%c",
  99. gd->bd->bi_enetaddr[0], gd->bd->bi_enetaddr[1],
  100. gd->bd->bi_enetaddr[2], gd->bd->bi_enetaddr[3],
  101. gd->bd->bi_enetaddr[4],
  102. gd->bd->bi_enetaddr[5],
  103. 0) ;
  104. printf("%s: Setting eth %s serial 0x%x\n", __FUNCTION__,
  105. ethaddr, serial);
  106. setenv(DEFAULT_ETH_ADDR, ethaddr);
  107. }
  108. /* IP-Adress update */
  109. ipstring = getenv("ipaddr");
  110. if (ipstring == 0)
  111. ipaddr = string_to_ip("172.25.1.99");
  112. else
  113. ipaddr = string_to_ip(ipstring);
  114. if ((ipaddr & 0xff) != (32 + hcu_get_slot())) {
  115. char tmp[22];
  116. ipaddr = (ipaddr & 0xffffff00) + 32 + hcu_get_slot();
  117. ip_to_string (ipaddr, tmp);
  118. printf("%s: enforce %s\n", __FUNCTION__, tmp);
  119. setenv("ipaddr", tmp);
  120. saveenv();
  121. }
  122. }