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