1
2
3
4
5
6
7
8
9
10
11#include <common.h>
12#include <ioports.h>
13#include <command.h>
14#include <malloc.h>
15#include <cli_hush.h>
16#include <net.h>
17#include <netdev.h>
18#include <asm/io.h>
19#include <linux/ctype.h>
20
21#if defined(CONFIG_POST)
22#include "post.h"
23#endif
24#include "common.h"
25#include <i2c.h>
26
27DECLARE_GLOBAL_DATA_PTR;
28
29
30
31
32
33
34
35
36
37
38
39
40
41int set_km_env(void)
42{
43 uchar buf[32];
44 unsigned int pnvramaddr;
45 unsigned int pram;
46 unsigned int varaddr;
47 unsigned int kernelmem;
48 char *p;
49 unsigned long rootfssize = 0;
50
51 pnvramaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM
52 - CONFIG_KM_PNVRAM;
53 sprintf((char *)buf, "0x%x", pnvramaddr);
54 setenv("pnvramaddr", (char *)buf);
55
56
57 p = getenv("rootfssize");
58 if (p != NULL)
59 strict_strtoul(p, 16, &rootfssize);
60 pram = (rootfssize + CONFIG_KM_RESERVED_PRAM + CONFIG_KM_PHRAM +
61 CONFIG_KM_PNVRAM) / 0x400;
62 sprintf((char *)buf, "0x%x", pram);
63 setenv("pram", (char *)buf);
64
65 varaddr = gd->ram_size - CONFIG_KM_RESERVED_PRAM - CONFIG_KM_PHRAM;
66 sprintf((char *)buf, "0x%x", varaddr);
67 setenv("varaddr", (char *)buf);
68
69 kernelmem = gd->ram_size - 0x400 * pram;
70 sprintf((char *)buf, "0x%x", kernelmem);
71 setenv("kernelmem", (char *)buf);
72
73 return 0;
74}
75
76#if defined(CONFIG_SYS_I2C_INIT_BOARD)
77static void i2c_write_start_seq(void)
78{
79 set_sda(1);
80 udelay(DELAY_HALF_PERIOD);
81 set_scl(1);
82 udelay(DELAY_HALF_PERIOD);
83 set_sda(0);
84 udelay(DELAY_HALF_PERIOD);
85 set_scl(0);
86 udelay(DELAY_HALF_PERIOD);
87}
88
89
90
91
92
93
94
95
96
97int i2c_make_abort(void)
98{
99 int scl_state = 0;
100 int sda_state = 0;
101 int i = 0;
102 int ret = 0;
103
104 if (!get_sda()) {
105 ret = -1;
106 while (i < 16) {
107 i++;
108 set_scl(0);
109 udelay(DELAY_ABORT_SEQ);
110 set_scl(1);
111 udelay(DELAY_ABORT_SEQ);
112 scl_state = get_scl();
113 sda_state = get_sda();
114 if (scl_state && sda_state) {
115 ret = 0;
116 break;
117 }
118 }
119 }
120 if (ret == 0)
121 for (i = 0; i < 5; i++)
122 i2c_write_start_seq();
123
124
125 udelay(DELAY_ABORT_SEQ);
126 set_scl(1);
127 udelay(DELAY_ABORT_SEQ);
128 set_sda(1);
129 get_sda();
130
131 return ret;
132}
133
134
135
136
137
138void i2c_init_board(void)
139{
140
141 i2c_make_abort();
142}
143#endif
144
145#if defined(CONFIG_KM_COMMON_ETH_INIT)
146int board_eth_init(bd_t *bis)
147{
148 if (ethernet_present())
149 return cpu_eth_init(bis);
150
151 return -1;
152}
153#endif
154
155
156
157
158
159
160static int do_setboardid(cmd_tbl_t *cmdtp, int flag, int argc,
161 char *const argv[])
162{
163 unsigned char buf[32];
164 char *p;
165
166 p = get_local_var("IVM_BoardId");
167 if (p == NULL) {
168 printf("can't get the IVM_Boardid\n");
169 return 1;
170 }
171 strcpy((char *)buf, p);
172 setenv("boardid", (char *)buf);
173 printf("set boardid=%s\n", buf);
174
175 p = get_local_var("IVM_HWKey");
176 if (p == NULL) {
177 printf("can't get the IVM_HWKey\n");
178 return 1;
179 }
180 strcpy((char *)buf, p);
181 setenv("hwkey", (char *)buf);
182 printf("set hwkey=%s\n", buf);
183 printf("Execute manually saveenv for persistent storage.\n");
184
185 return 0;
186}
187
188U_BOOT_CMD(km_setboardid, 1, 0, do_setboardid, "setboardid", "read out bid and "
189 "hwkey from IVM and set in environment");
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206static int do_checkboardidhwk(cmd_tbl_t *cmdtp, int flag, int argc,
207 char *const argv[])
208{
209 unsigned long ivmbid = 0, ivmhwkey = 0;
210 unsigned long envbid = 0, envhwkey = 0;
211 char *p;
212 int verbose = argc > 1 && *argv[1] == 'v';
213 int rc = 0;
214
215
216
217
218
219 p = get_local_var("IVM_BoardId");
220 if (p == NULL) {
221 printf("can't get the IVM_Boardid\n");
222 return 1;
223 }
224 rc = strict_strtoul(p, 16, &ivmbid);
225
226 p = get_local_var("IVM_HWKey");
227 if (p == NULL) {
228 printf("can't get the IVM_HWKey\n");
229 return 1;
230 }
231 rc = strict_strtoul(p, 16, &ivmhwkey);
232
233 if (!ivmbid || !ivmhwkey) {
234 printf("Error: IVM_BoardId and/or IVM_HWKey not set!\n");
235 return rc;
236 }
237
238
239 p = getenv("boardid");
240 if (p != NULL)
241 rc = strict_strtoul(p, 16, &envbid);
242 p = getenv("hwkey");
243 if (p != NULL)
244 rc = strict_strtoul(p, 16, &envhwkey);
245
246 if (rc != 0) {
247 printf("strict_strtoul returns error: %d", rc);
248 return rc;
249 }
250
251 if (!envbid || !envhwkey) {
252
253
254
255
256 char *bidhwklist = getenv("boardIdListHex");
257
258 if (bidhwklist) {
259 int found = 0;
260 char *rest = bidhwklist;
261 char *endp;
262
263 if (verbose) {
264 printf("IVM_BoardId: %ld, IVM_HWKey=%ld\n",
265 ivmbid, ivmhwkey);
266 printf("boardIdHwKeyList: %s\n",
267 bidhwklist);
268 }
269 while (!found) {
270
271 unsigned long bid = 0;
272 unsigned long hwkey = 0;
273
274 while (*rest && !isxdigit(*rest))
275 rest++;
276
277
278
279
280 bid = simple_strtoul(rest, &endp, 16);
281
282 if (*endp == '_') {
283 rest = endp + 1;
284
285
286
287
288 hwkey = simple_strtoul(rest, &endp, 16);
289 rest = endp;
290 while (*rest && !isxdigit(*rest))
291 rest++;
292 }
293 if ((!bid) || (!hwkey)) {
294
295 break;
296 }
297 if (verbose) {
298 printf("trying bid=0x%lX, hwkey=%ld\n",
299 bid, hwkey);
300 }
301
302
303
304
305
306
307 if ((bid == ivmbid) && (hwkey == ivmhwkey)) {
308 char buf[10];
309
310 found = 1;
311 envbid = bid;
312 envhwkey = hwkey;
313 sprintf(buf, "%lx", bid);
314 setenv("boardid", buf);
315 sprintf(buf, "%lx", hwkey);
316 setenv("hwkey", buf);
317 }
318 }
319 }
320 }
321
322
323 if ((ivmbid == envbid) && (ivmhwkey == envhwkey)) {
324 printf("boardid=0x%3lX, hwkey=%ld\n", envbid, envhwkey);
325 rc = 0;
326 } else {
327 printf("Error: env boardid=0x%3lX, hwkey=%ld\n", envbid,
328 envhwkey);
329 printf(" IVM bId=0x%3lX, hwKey=%ld\n", ivmbid, ivmhwkey);
330 rc = 1;
331 }
332 return rc;
333}
334
335U_BOOT_CMD(km_checkbidhwk, 2, 0, do_checkboardidhwk,
336 "check boardid and hwkey",
337 "[v]\n - check environment parameter "\
338 "\"boardIdListHex\" against stored boardid and hwkey "\
339 "from the IVM\n v: verbose output"
340);
341
342
343
344
345
346
347static int do_checktestboot(cmd_tbl_t *cmdtp, int flag, int argc,
348 char *const argv[])
349{
350 int testpin = 0;
351 char *s = NULL;
352 int testboot = 0;
353 int verbose = argc > 1 && *argv[1] == 'v';
354
355#if defined(CONFIG_POST)
356 testpin = post_hotkeys_pressed();
357#endif
358#if defined(CONFIG_MGCOGE3NE)
359 testpin = get_testpin();
360#endif
361 s = getenv("test_bank");
362
363 testboot = (testpin != 0) && (s);
364 if (verbose) {
365 printf("testpin = %d\n", testpin);
366
367 printf("test_bank = %s\n", s ? s : "not set");
368 printf("boot test app : %s\n", (testboot) ? "yes" : "no");
369 }
370
371 return !testboot;
372}
373
374U_BOOT_CMD(km_checktestboot, 2, 0, do_checktestboot,
375 "check if testpin is asserted",
376 "[v]\n v - verbose output"
377);
378