blob: b50b4af2af568bef25c797bca7bc858f535e4b87 [file] [log] [blame]
Niklaus Gigere8397fc72007-07-27 11:38:26 +02001/*
Niklaus Giger69b06342008-01-17 12:53:56 +01002 *(C) Copyright 2005-2008 Netstal Maschinen AG
Niklaus Gigere8397fc72007-07-27 11:38:26 +02003 * 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
21#include <common.h>
22#include <command.h>
Niklaus Giger69b06342008-01-17 12:53:56 +010023#include <net.h>
24#include "nm.h"
Niklaus Gigere8397fc72007-07-27 11:38:26 +020025
Niklaus Giger69b06342008-01-17 12:53:56 +010026DECLARE_GLOBAL_DATA_PTR;
27
28#define DEFAULT_ETH_ADDR "ethaddr"
29
30typedef struct {u8 id; char *name;} generation_info;
31
32generation_info generations[7] = {
33 {HW_GENERATION_HCU2, "HCU2"},
34 {HW_GENERATION_HCU3, "HCU3"},
35 {HW_GENERATION_HCU4, "HCU4"},
36 {HW_GENERATION_HCU5, "HCU5"},
37 {HW_GENERATION_MCU, "MCU"},
38 {HW_GENERATION_MCU20, "MCU20"},
39 {HW_GENERATION_MCU25, "MCU25"},
40};
41
42void nm_show_print(int generation, int index, int hw_capabilities)
Niklaus Gigere8397fc72007-07-27 11:38:26 +020043{
Niklaus Giger69b06342008-01-17 12:53:56 +010044 int j;
45 char *generationName=0;
46
47 /* reset ANSI terminal color mode */
48 printf("\x1B""[0m""Netstal Maschinen AG: ");
49 for (j=0; j < (sizeof(generations)/sizeof(generations[0])); j++) {
50 if (generations[j].id == generation) {
51 generationName = generations[j].name;
52 break;
53 }
54 }
55 printf("%s: index %d HW 0x%x\n", generationName, index, hw_capabilities);
56 for (j = 0;j < 6; j++) {
57 hcu_led_set(1 << j);
58 udelay(200 * 1000);
59 }
Niklaus Gigere8397fc72007-07-27 11:38:26 +020060}
61
Niklaus Giger69b06342008-01-17 12:53:56 +010062void set_params_for_sw_install(int install_requested, char *board_name )
63{
64 if (install_requested) {
65 char string[128];
66
67 printf("\n\n%s SW-Installation: %d patching boot parameters\n",
68 board_name, install_requested);
69 setenv("bootdelay", "0");
70 setenv("loadaddr", "0x01000000");
71 setenv("serverip", "172.25.1.1");
72 setenv("bootcmd", "run install");
73 sprintf(string, "tftp ${loadaddr} admin/sw_on_hd; "
74 "tftp ${loadaddr} installer/%s_sw_inst; "
75 "run boot_sw_inst", board_name);
76 setenv("install", string);
77 sprintf(string, "setenv bootargs emac(0,0)c:%s/%s_sw_inst "
78 "e=${ipaddr} h=${serverip} f=0x1000; "
79 "bootvx ${loadaddr}\0",
80 board_name, board_name);
81 setenv("boot_sw_inst", string);
82 }
83}
84
85void common_misc_init_r(void)
86{
87 char *s = getenv(DEFAULT_ETH_ADDR);
88 char *e;
89 int i;
90 u32 serial = get_serial_number();
91 IPaddr_t ipaddr;
92 char *ipstring;
93
94 for (i = 0; i < 6; ++i) {
95 gd->bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0;
96 if (s)
97 s = (*e) ? e + 1 : e;
98 }
99
100 if (gd->bd->bi_enetaddr[3] == 0 &&
101 gd->bd->bi_enetaddr[4] == 0 &&
102 gd->bd->bi_enetaddr[5] == 0) {
103 char ethaddr[22];
104
105 /* Must be in sync with CONFIG_ETHADDR */
106 gd->bd->bi_enetaddr[0] = 0x00;
107 gd->bd->bi_enetaddr[1] = 0x60;
108 gd->bd->bi_enetaddr[2] = 0x13;
109 gd->bd->bi_enetaddr[3] = (serial >> 16) & 0xff;
110 gd->bd->bi_enetaddr[4] = (serial >> 8) & 0xff;
111 gd->bd->bi_enetaddr[5] = hcu_get_slot();
112 sprintf(ethaddr, "%02X:%02X:%02X:%02X:%02X:%02X\0",
113 gd->bd->bi_enetaddr[0], gd->bd->bi_enetaddr[1],
114 gd->bd->bi_enetaddr[2], gd->bd->bi_enetaddr[3],
115 gd->bd->bi_enetaddr[4], gd->bd->bi_enetaddr[5]) ;
116 printf("%s: Setting eth %s serial 0x%x\n", __FUNCTION__,
117 ethaddr, serial);
118 setenv(DEFAULT_ETH_ADDR, ethaddr);
119 }
120
121 /* IP-Adress update */
122 ipstring = getenv("ipaddr");
123 if (ipstring == 0)
124 ipaddr = string_to_ip("172.25.1.99");
125 else
126 ipaddr = string_to_ip(ipstring);
127 if ((ipaddr & 0xff) != (32 + hcu_get_slot())) {
128 char tmp[22];
129
130 ipaddr = (ipaddr & 0xffffff00) + 32 + hcu_get_slot();
131 ip_to_string (ipaddr, tmp);
132 printf("%s: enforce %s\n", __FUNCTION__, tmp);
133 setenv("ipaddr", tmp);
134 saveenv();
135 }
136}
137