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