Blame view
post/post.c
9.75 KB
a042ac843
|
1 2 3 4 |
/* * (C) Copyright 2002 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * |
1a4596601
|
5 |
* SPDX-License-Identifier: GPL-2.0+ |
a042ac843
|
6 7 8 |
*/ #include <common.h> |
52cb4d4fb
|
9 |
#include <stdio_dev.h> |
a042ac843
|
10 |
#include <watchdog.h> |
c90a4dd79
|
11 |
#include <div64.h> |
a042ac843
|
12 |
#include <post.h> |
9146d1382
|
13 14 15 |
#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO #include <asm/gpio.h> #endif |
56f94be3e
|
16 17 18 |
#ifdef CONFIG_LOGBUFFER #include <logbuff.h> #endif |
d87080b72
|
19 |
DECLARE_GLOBAL_DATA_PTR; |
a042ac843
|
20 21 22 |
#define POST_MAX_NUMBER 32 #define BOOTMODE_MAGIC 0xDEAD0000 |
e92372c8a
|
23 |
int post_init_f(void) |
4532cb696
|
24 |
{ |
4532cb696
|
25 26 27 28 29 |
int res = 0; unsigned int i; for (i = 0; i < post_list_size; i++) { struct post_test *test = post_list + i; |
50da83766
|
30 |
if (test->init_f && test->init_f()) |
4532cb696
|
31 |
res = -1; |
4532cb696
|
32 |
} |
8bde7f776
|
33 |
|
4532cb696
|
34 35 |
gd->post_init_f_time = post_time_ms(0); if (!gd->post_init_f_time) |
e92372c8a
|
36 37 |
printf("%s: post_time_ms not implemented ", __FILE__); |
4532cb696
|
38 39 40 |
return res; } |
39ff7d5f4
|
41 42 43 44 45 46 47 48 |
/* * Supply a default implementation for post_hotkeys_pressed() for boards * without hotkey support. We always return 0 here, so that the * long-running tests won't be started. * * Boards with hotkey support can override this weak default function * by defining one in their board specific code. */ |
002ad7b87
|
49 |
__weak int post_hotkeys_pressed(void) |
39ff7d5f4
|
50 |
{ |
9146d1382
|
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO int ret; unsigned gpio = CONFIG_SYS_POST_HOTKEYS_GPIO; ret = gpio_request(gpio, "hotkeys"); if (ret) { printf("POST: gpio hotkey request failed "); return 0; } gpio_direction_input(gpio); ret = gpio_get_value(gpio); gpio_free(gpio); return ret; #endif |
39ff7d5f4
|
68 69 |
return 0; /* No hotkeys supported */ } |
39ff7d5f4
|
70 |
|
e92372c8a
|
71 |
void post_bootmode_init(void) |
a042ac843
|
72 |
{ |
e92372c8a
|
73 |
int bootmode = post_bootmode_get(0); |
27b207fd0
|
74 |
int newword; |
42d1f0394
|
75 |
|
e92372c8a
|
76 |
if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST)) |
27b207fd0
|
77 |
newword = BOOTMODE_MAGIC | POST_SLOWTEST; |
e92372c8a
|
78 |
else if (bootmode == 0) |
27b207fd0
|
79 |
newword = BOOTMODE_MAGIC | POST_POWERON; |
e92372c8a
|
80 |
else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST) |
27b207fd0
|
81 |
newword = BOOTMODE_MAGIC | POST_NORMAL; |
e92372c8a
|
82 |
else |
27b207fd0
|
83 |
/* Use old value */ |
50da83766
|
84 |
newword = post_word_load() & ~POST_COLDBOOT; |
a042ac843
|
85 |
|
27b207fd0
|
86 |
if (bootmode == 0) |
27b207fd0
|
87 88 |
/* We are booting after power-on */ newword |= POST_COLDBOOT; |
27b207fd0
|
89 |
|
e92372c8a
|
90 |
post_word_store(newword); |
27b207fd0
|
91 |
|
228f29ac6
|
92 93 |
/* Reset activity record */ gd->post_log_word = 0; |
79843950b
|
94 |
gd->post_log_res = 0; |
a042ac843
|
95 |
} |
e92372c8a
|
96 |
int post_bootmode_get(unsigned int *last_test) |
a042ac843
|
97 |
{ |
e92372c8a
|
98 |
unsigned long word = post_word_load(); |
a042ac843
|
99 |
int bootmode; |
e92372c8a
|
100 |
if ((word & 0xFFFF0000) != BOOTMODE_MAGIC) |
a042ac843
|
101 |
return 0; |
a042ac843
|
102 |
|
27b207fd0
|
103 |
bootmode = word & 0x7F; |
a042ac843
|
104 |
|
e92372c8a
|
105 |
if (last_test && (bootmode & POST_POWERTEST)) |
a042ac843
|
106 |
*last_test = (word >> 8) & 0xFF; |
a042ac843
|
107 108 109 |
return bootmode; } |
228f29ac6
|
110 |
/* POST tests run before relocation only mark status bits .... */ |
e92372c8a
|
111 |
static void post_log_mark_start(unsigned long testid) |
228f29ac6
|
112 |
{ |
79843950b
|
113 |
gd->post_log_word |= testid; |
228f29ac6
|
114 |
} |
e92372c8a
|
115 |
static void post_log_mark_succ(unsigned long testid) |
228f29ac6
|
116 |
{ |
79843950b
|
117 |
gd->post_log_res |= testid; |
228f29ac6
|
118 119 120 |
} /* ... and the messages are output once we are relocated */ |
e92372c8a
|
121 |
void post_output_backlog(void) |
228f29ac6
|
122 |
{ |
228f29ac6
|
123 124 125 |
int j; for (j = 0; j < post_list_size; j++) { |
79843950b
|
126 |
if (gd->post_log_word & (post_list[j].testid)) { |
50da83766
|
127 |
post_log("POST %s ", post_list[j].cmd); |
79843950b
|
128 |
if (gd->post_log_res & post_list[j].testid) |
50da83766
|
129 130 |
post_log("PASSED "); |
63e73c9a8
|
131 |
else { |
e92372c8a
|
132 133 |
post_log("FAILED "); |
770605e4f
|
134 |
bootstage_error(BOOTSTAGE_ID_POST_FAIL_R); |
63e73c9a8
|
135 |
} |
228f29ac6
|
136 137 138 |
} } } |
e92372c8a
|
139 |
static void post_bootmode_test_on(unsigned int last_test) |
a042ac843
|
140 |
{ |
e92372c8a
|
141 |
unsigned long word = post_word_load(); |
a042ac843
|
142 143 144 145 |
word |= POST_POWERTEST; word |= (last_test & 0xFF) << 8; |
e92372c8a
|
146 |
post_word_store(word); |
a042ac843
|
147 |
} |
e92372c8a
|
148 |
static void post_bootmode_test_off(void) |
a042ac843
|
149 |
{ |
e92372c8a
|
150 |
unsigned long word = post_word_load(); |
a042ac843
|
151 152 |
word &= ~POST_POWERTEST; |
e92372c8a
|
153 |
post_word_store(word); |
a042ac843
|
154 |
} |
212a0cafa
|
155 156 |
#ifndef CONFIG_POST_SKIP_ENV_FLAGS static void post_get_env_flags(int *test_flags) |
a042ac843
|
157 |
{ |
e262efe35
|
158 159 160 161 |
int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST, POST_CRITICAL }; char *var[] = { "post_poweron", "post_normal", "post_slowtest", "post_critical" }; |
d2397817f
|
162 |
int varnum = ARRAY_SIZE(var); |
a042ac843
|
163 164 165 166 167 |
char list[128]; /* long enough for POST list */ char *name; char *s; int last; int i, j; |
a042ac843
|
168 |
for (i = 0; i < varnum; i++) { |
50da83766
|
169 |
if (getenv_f(var[i], list, sizeof(list)) <= 0) |
a042ac843
|
170 |
continue; |
50da83766
|
171 |
for (j = 0; j < post_list_size; j++) |
a042ac843
|
172 |
test_flags[j] &= ~flag[i]; |
a042ac843
|
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
last = 0; name = list; while (!last) { while (*name && *name == ' ') name++; if (*name == 0) break; s = name + 1; while (*s && *s != ' ') s++; if (*s == 0) last = 1; else *s = 0; for (j = 0; j < post_list_size; j++) { |
50da83766
|
190 |
if (strcmp(post_list[j].cmd, name) == 0) { |
a042ac843
|
191 192 193 194 |
test_flags[j] |= flag[i]; break; } } |
e92372c8a
|
195 |
if (j == post_list_size) |
50da83766
|
196 197 |
printf("No such test: %s ", name); |
a042ac843
|
198 199 200 201 |
name = s + 1; } } |
212a0cafa
|
202 203 204 205 206 207 208 209 210 211 212 213 214 |
} #endif static void post_get_flags(int *test_flags) { int j; for (j = 0; j < post_list_size; j++) test_flags[j] = post_list[j].flags; #ifndef CONFIG_POST_SKIP_ENV_FLAGS post_get_env_flags(test_flags); #endif |
6dff55297
|
215 |
|
e92372c8a
|
216 217 |
for (j = 0; j < post_list_size; j++) if (test_flags[j] & POST_POWERON) |
6dff55297
|
218 |
test_flags[j] |= POST_SLOWTEST; |
a042ac843
|
219 |
} |
002ad7b87
|
220 |
__weak void show_post_progress(unsigned int test_num, int before, int result) |
e070a56c7
|
221 222 |
{ } |
e070a56c7
|
223 |
|
e92372c8a
|
224 |
static int post_run_single(struct post_test *test, |
a042ac843
|
225 226 227 228 |
int test_flags, int flags, unsigned int i) { if ((flags & test_flags & POST_ALWAYS) && (flags & test_flags & POST_MEM)) { |
50da83766
|
229 |
WATCHDOG_RESET(); |
a042ac843
|
230 231 |
if (!(flags & POST_REBOOT)) { |
e92372c8a
|
232 233 234 |
if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) { post_bootmode_test_on( |
e262efe35
|
235 236 |
(gd->flags & GD_FLG_POSTFAIL) ? POST_FAIL_SAVE | i : i); |
a042ac843
|
237 |
} |
228f29ac6
|
238 |
if (test_flags & POST_PREREL) |
e92372c8a
|
239 |
post_log_mark_start(test->testid); |
228f29ac6
|
240 |
else |
e92372c8a
|
241 |
post_log("POST %s ", test->cmd); |
a042ac843
|
242 |
} |
e070a56c7
|
243 |
show_post_progress(i, POST_BEFORE, POST_FAILED); |
228f29ac6
|
244 |
if (test_flags & POST_PREREL) { |
50da83766
|
245 |
if ((*test->test)(flags) == 0) { |
e92372c8a
|
246 |
post_log_mark_succ(test->testid); |
e070a56c7
|
247 |
show_post_progress(i, POST_AFTER, POST_PASSED); |
50da83766
|
248 |
} else { |
e070a56c7
|
249 |
show_post_progress(i, POST_AFTER, POST_FAILED); |
28a385065
|
250 251 252 253 254 |
if (test_flags & POST_CRITICAL) gd->flags |= GD_FLG_POSTFAIL; if (test_flags & POST_STOP) gd->flags |= GD_FLG_POSTSTOP; } |
228f29ac6
|
255 |
} else { |
975afc34d
|
256 257 258 |
if ((*test->test)(flags) != 0) { post_log("FAILED "); |
770605e4f
|
259 |
bootstage_error(BOOTSTAGE_ID_POST_FAIL_R); |
975afc34d
|
260 261 262 263 264 265 266 267 268 269 |
show_post_progress(i, POST_AFTER, POST_FAILED); if (test_flags & POST_CRITICAL) gd->flags |= GD_FLG_POSTFAIL; if (test_flags & POST_STOP) gd->flags |= GD_FLG_POSTSTOP; } else { post_log("PASSED "); show_post_progress(i, POST_AFTER, POST_PASSED); } |
228f29ac6
|
270 |
} |
a042ac843
|
271 |
|
50da83766
|
272 |
if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) |
e92372c8a
|
273 |
post_bootmode_test_off(); |
a042ac843
|
274 275 276 277 278 279 |
return 0; } else { return -1; } } |
50da83766
|
280 |
int post_run(char *name, int flags) |
a042ac843
|
281 282 283 |
{ unsigned int i; int test_flags[POST_MAX_NUMBER]; |
e92372c8a
|
284 |
post_get_flags(test_flags); |
a042ac843
|
285 286 287 |
if (name == NULL) { unsigned int last; |
28a385065
|
288 289 |
if (gd->flags & GD_FLG_POSTSTOP) return 0; |
e92372c8a
|
290 |
if (post_bootmode_get(&last) & POST_POWERTEST) { |
e262efe35
|
291 292 293 294 |
if (last & POST_FAIL_SAVE) { last &= ~POST_FAIL_SAVE; gd->flags |= GD_FLG_POSTFAIL; } |
a042ac843
|
295 296 297 |
if (last < post_list_size && (flags & test_flags[last] & POST_ALWAYS) && (flags & test_flags[last] & POST_MEM)) { |
e92372c8a
|
298 |
post_run_single(post_list + last, |
ea909b760
|
299 300 |
test_flags[last], flags | POST_REBOOT, last); |
a042ac843
|
301 302 |
for (i = last + 1; i < post_list_size; i++) { |
28a385065
|
303 304 |
if (gd->flags & GD_FLG_POSTSTOP) break; |
e92372c8a
|
305 |
post_run_single(post_list + i, |
ea909b760
|
306 307 |
test_flags[i], flags, i); |
a042ac843
|
308 309 310 311 |
} } } else { for (i = 0; i < post_list_size; i++) { |
28a385065
|
312 313 |
if (gd->flags & GD_FLG_POSTSTOP) break; |
e92372c8a
|
314 |
post_run_single(post_list + i, |
ea909b760
|
315 316 |
test_flags[i], flags, i); |
a042ac843
|
317 318 319 320 321 322 |
} } return 0; } else { for (i = 0; i < post_list_size; i++) { |
50da83766
|
323 |
if (strcmp(post_list[i].cmd, name) == 0) |
a042ac843
|
324 325 326 327 |
break; } if (i < post_list_size) { |
5744ddc66
|
328 |
WATCHDOG_RESET(); |
e92372c8a
|
329 |
return post_run_single(post_list + i, |
a042ac843
|
330 331 332 333 334 335 336 |
test_flags[i], flags, i); } else { return -1; } } } |
e92372c8a
|
337 |
static int post_info_single(struct post_test *test, int full) |
a042ac843
|
338 339 340 |
{ if (test->flags & POST_MANUAL) { if (full) |
e92372c8a
|
341 342 |
printf("%s - %s " |
a042ac843
|
343 344 345 |
" %s ", test->cmd, test->name, test->desc); else |
e92372c8a
|
346 347 |
printf(" %-15s - %s ", test->cmd, test->name); |
a042ac843
|
348 349 350 351 352 353 |
return 0; } else { return -1; } } |
50da83766
|
354 |
int post_info(char *name) |
a042ac843
|
355 356 357 358 |
{ unsigned int i; if (name == NULL) { |
e92372c8a
|
359 360 |
for (i = 0; i < post_list_size; i++) post_info_single(post_list + i, 0); |
a042ac843
|
361 362 363 364 |
return 0; } else { for (i = 0; i < post_list_size; i++) { |
50da83766
|
365 |
if (strcmp(post_list[i].cmd, name) == 0) |
a042ac843
|
366 367 |
break; } |
50da83766
|
368 |
if (i < post_list_size) |
e92372c8a
|
369 |
return post_info_single(post_list + i, 1); |
50da83766
|
370 |
else |
a042ac843
|
371 |
return -1; |
a042ac843
|
372 373 |
} } |
e92372c8a
|
374 |
int post_log(char *format, ...) |
a042ac843
|
375 376 |
{ va_list args; |
6d0f6bcf3
|
377 |
char printbuffer[CONFIG_SYS_PBSIZE]; |
a042ac843
|
378 |
|
50da83766
|
379 |
va_start(args, format); |
a042ac843
|
380 381 382 383 |
/* For this to work, printbuffer must be larger than * anything we ever want to print. */ |
4d6402b01
|
384 |
vsprintf(printbuffer, format, args); |
50da83766
|
385 |
va_end(args); |
a042ac843
|
386 |
|
56f94be3e
|
387 |
#ifdef CONFIG_LOGBUFFER |
228f29ac6
|
388 |
/* Send to the logbuffer */ |
e92372c8a
|
389 |
logbuff_log(printbuffer); |
56f94be3e
|
390 |
#else |
a042ac843
|
391 |
/* Send to the stdout file */ |
e92372c8a
|
392 |
puts(printbuffer); |
56f94be3e
|
393 |
#endif |
a042ac843
|
394 395 396 |
return 0; } |
2e5167cca
|
397 |
#ifdef CONFIG_NEEDS_MANUAL_RELOC |
e92372c8a
|
398 |
void post_reloc(void) |
a042ac843
|
399 |
{ |
a042ac843
|
400 401 402 403 404 405 406 407 408 409 |
unsigned int i; /* * We have to relocate the test table manually */ for (i = 0; i < post_list_size; i++) { ulong addr; struct post_test *test = post_list + i; if (test->name) { |
50da83766
|
410 |
addr = (ulong)(test->name) + gd->reloc_off; |
e92372c8a
|
411 |
test->name = (char *)addr; |
a042ac843
|
412 413 414 |
} if (test->cmd) { |
50da83766
|
415 |
addr = (ulong)(test->cmd) + gd->reloc_off; |
e92372c8a
|
416 |
test->cmd = (char *)addr; |
a042ac843
|
417 418 419 |
} if (test->desc) { |
50da83766
|
420 |
addr = (ulong)(test->desc) + gd->reloc_off; |
e92372c8a
|
421 |
test->desc = (char *)addr; |
a042ac843
|
422 423 424 |
} if (test->test) { |
50da83766
|
425 |
addr = (ulong)(test->test) + gd->reloc_off; |
a042ac843
|
426 427 |
test->test = (int (*)(int flags)) addr; } |
4532cb696
|
428 429 |
if (test->init_f) { |
50da83766
|
430 |
addr = (ulong)(test->init_f) + gd->reloc_off; |
4532cb696
|
431 432 433 434 |
test->init_f = (int (*)(void)) addr; } if (test->reloc) { |
50da83766
|
435 |
addr = (ulong)(test->reloc) + gd->reloc_off; |
4532cb696
|
436 |
test->reloc = (void (*)(void)) addr; |
8bde7f776
|
437 |
|
4532cb696
|
438 439 |
test->reloc(); } |
a042ac843
|
440 441 |
} } |
521af04d8
|
442 |
#endif |
a042ac843
|
443 |
|
4532cb696
|
444 445 446 447 448 449 450 |
/* * Some tests (e.g. SYSMON) need the time when post_init_f started, * but we cannot use get_timer() at this point. * * On PowerPC we implement it using the timebase register. */ |
e92372c8a
|
451 |
unsigned long post_time_ms(unsigned long base) |
4532cb696
|
452 |
{ |
4e518b887
|
453 |
#if defined(CONFIG_PPC) || defined(CONFIG_BLACKFIN) || defined(CONFIG_ARM) |
c90a4dd79
|
454 |
return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ) |
e92372c8a
|
455 |
- base; |
4532cb696
|
456 |
#else |
ad5bb451a
|
457 |
#warning "Not implemented yet" |
4532cb696
|
458 459 460 |
return 0; /* Not implemented yet */ #endif } |