3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 #include <stdio_dev.h>
29 #ifdef CONFIG_LOGBUFFER
33 DECLARE_GLOBAL_DATA_PTR;
35 #define POST_MAX_NUMBER 32
37 #define BOOTMODE_MAGIC 0xDEAD0000
39 int post_init_f (void)
44 for (i = 0; i < post_list_size; i++) {
45 struct post_test *test = post_list + i;
47 if (test->init_f && test->init_f()) {
52 gd->post_init_f_time = post_time_ms(0);
53 if (!gd->post_init_f_time)
55 printf("post/post.c: post_time_ms seems not to be implemented\n");
62 * Supply a default implementation for post_hotkeys_pressed() for boards
63 * without hotkey support. We always return 0 here, so that the
64 * long-running tests won't be started.
66 * Boards with hotkey support can override this weak default function
67 * by defining one in their board specific code.
69 int __post_hotkeys_pressed(void)
71 return 0; /* No hotkeys supported */
73 int post_hotkeys_pressed(void)
74 __attribute__((weak, alias("__post_hotkeys_pressed")));
77 void post_bootmode_init (void)
79 int bootmode = post_bootmode_get (0);
82 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST)) {
83 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
84 } else if (bootmode == 0) {
85 newword = BOOTMODE_MAGIC | POST_POWERON;
86 } else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST) {
87 newword = BOOTMODE_MAGIC | POST_NORMAL;
90 newword = post_word_load () & ~POST_COLDBOOT;
95 /* We are booting after power-on */
96 newword |= POST_COLDBOOT;
99 post_word_store (newword);
101 /* Reset activity record */
102 gd->post_log_word = 0;
105 int post_bootmode_get (unsigned int *last_test)
107 unsigned long word = post_word_load ();
110 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC) {
114 bootmode = word & 0x7F;
116 if (last_test && (bootmode & POST_POWERTEST)) {
117 *last_test = (word >> 8) & 0xFF;
123 /* POST tests run before relocation only mark status bits .... */
124 static void post_log_mark_start ( unsigned long testid )
126 gd->post_log_word |= (testid)<<16;
129 static void post_log_mark_succ ( unsigned long testid )
131 gd->post_log_word |= testid;
134 /* ... and the messages are output once we are relocated */
135 void post_output_backlog ( void )
139 for (j = 0; j < post_list_size; j++) {
140 if (gd->post_log_word & (post_list[j].testid<<16)) {
141 post_log ("POST %s ", post_list[j].cmd);
142 if (gd->post_log_word & post_list[j].testid)
143 post_log ("PASSED\n");
145 post_log ("FAILED\n");
146 show_boot_progress (-31);
152 static void post_bootmode_test_on (unsigned int last_test)
154 unsigned long word = post_word_load ();
156 word |= POST_POWERTEST;
158 word |= (last_test & 0xFF) << 8;
160 post_word_store (word);
163 static void post_bootmode_test_off (void)
165 unsigned long word = post_word_load ();
167 word &= ~POST_POWERTEST;
169 post_word_store (word);
172 static void post_get_flags (int *test_flags)
174 int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST,
176 char *var[] = { "post_poweron", "post_normal", "post_slowtest",
178 int varnum = sizeof (var) / sizeof (var[0]);
179 char list[128]; /* long enough for POST list */
185 for (j = 0; j < post_list_size; j++) {
186 test_flags[j] = post_list[j].flags;
189 for (i = 0; i < varnum; i++) {
190 if (getenv_f(var[i], list, sizeof (list)) <= 0)
193 for (j = 0; j < post_list_size; j++) {
194 test_flags[j] &= ~flag[i];
200 while (*name && *name == ' ')
205 while (*s && *s != ' ')
212 for (j = 0; j < post_list_size; j++) {
213 if (strcmp (post_list[j].cmd, name) == 0) {
214 test_flags[j] |= flag[i];
219 if (j == post_list_size) {
220 printf ("No such test: %s\n", name);
227 for (j = 0; j < post_list_size; j++) {
228 if (test_flags[j] & POST_POWERON) {
229 test_flags[j] |= POST_SLOWTEST;
234 void __show_post_progress (unsigned int test_num, int before, int result)
237 void show_post_progress (unsigned int, int, int)
238 __attribute__((weak, alias("__show_post_progress")));
240 static int post_run_single (struct post_test *test,
241 int test_flags, int flags, unsigned int i)
243 if ((flags & test_flags & POST_ALWAYS) &&
244 (flags & test_flags & POST_MEM)) {
247 if (!(flags & POST_REBOOT)) {
248 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
249 post_bootmode_test_on (
250 (gd->flags & GD_FLG_POSTFAIL) ?
251 POST_FAIL_SAVE | i : i);
254 if (test_flags & POST_PREREL)
255 post_log_mark_start ( test->testid );
257 post_log ("POST %s ", test->cmd);
260 show_post_progress(i, POST_BEFORE, POST_FAILED);
262 if (test_flags & POST_PREREL) {
263 if ((*test->test) (flags) == 0) {
264 post_log_mark_succ ( test->testid );
265 show_post_progress(i, POST_AFTER, POST_PASSED);
268 show_post_progress(i, POST_AFTER, POST_FAILED);
269 if (test_flags & POST_CRITICAL)
270 gd->flags |= GD_FLG_POSTFAIL;
271 if (test_flags & POST_STOP)
272 gd->flags |= GD_FLG_POSTSTOP;
275 if ((*test->test) (flags) != 0) {
276 post_log ("FAILED\n");
277 show_boot_progress (-32);
278 show_post_progress(i, POST_AFTER, POST_FAILED);
279 if (test_flags & POST_CRITICAL)
280 gd->flags |= GD_FLG_POSTFAIL;
281 if (test_flags & POST_STOP)
282 gd->flags |= GD_FLG_POSTSTOP;
285 post_log ("PASSED\n");
286 show_post_progress(i, POST_AFTER, POST_PASSED);
289 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
290 post_bootmode_test_off ();
299 int post_run (char *name, int flags)
302 int test_flags[POST_MAX_NUMBER];
304 post_get_flags (test_flags);
309 if (gd->flags & GD_FLG_POSTSTOP)
312 if (post_bootmode_get (&last) & POST_POWERTEST) {
313 if (last & POST_FAIL_SAVE) {
314 last &= ~POST_FAIL_SAVE;
315 gd->flags |= GD_FLG_POSTFAIL;
317 if (last < post_list_size &&
318 (flags & test_flags[last] & POST_ALWAYS) &&
319 (flags & test_flags[last] & POST_MEM)) {
321 post_run_single (post_list + last,
323 flags | POST_REBOOT, last);
325 for (i = last + 1; i < post_list_size; i++) {
326 if (gd->flags & GD_FLG_POSTSTOP)
328 post_run_single (post_list + i,
334 for (i = 0; i < post_list_size; i++) {
335 if (gd->flags & GD_FLG_POSTSTOP)
337 post_run_single (post_list + i,
345 for (i = 0; i < post_list_size; i++) {
346 if (strcmp (post_list[i].cmd, name) == 0)
350 if (i < post_list_size) {
352 return post_run_single (post_list + i,
361 static int post_info_single (struct post_test *test, int full)
363 if (test->flags & POST_MANUAL) {
366 " %s\n", test->cmd, test->name, test->desc);
368 printf (" %-15s - %s\n", test->cmd, test->name);
376 int post_info (char *name)
381 for (i = 0; i < post_list_size; i++) {
382 post_info_single (post_list + i, 0);
387 for (i = 0; i < post_list_size; i++) {
388 if (strcmp (post_list[i].cmd, name) == 0)
392 if (i < post_list_size) {
393 return post_info_single (post_list + i, 1);
400 int post_log (char *format, ...)
404 char printbuffer[CONFIG_SYS_PBSIZE];
406 va_start (args, format);
408 /* For this to work, printbuffer must be larger than
409 * anything we ever want to print.
411 i = vsprintf (printbuffer, format, args);
414 #ifdef CONFIG_LOGBUFFER
415 /* Send to the logbuffer */
416 logbuff_log (printbuffer);
418 /* Send to the stdout file */
425 #ifdef CONFIG_NEEDS_MANUAL_RELOC
426 void post_reloc (void)
431 * We have to relocate the test table manually
433 for (i = 0; i < post_list_size; i++) {
435 struct post_test *test = post_list + i;
438 addr = (ulong) (test->name) + gd->reloc_off;
439 test->name = (char *) addr;
443 addr = (ulong) (test->cmd) + gd->reloc_off;
444 test->cmd = (char *) addr;
448 addr = (ulong) (test->desc) + gd->reloc_off;
449 test->desc = (char *) addr;
453 addr = (ulong) (test->test) + gd->reloc_off;
454 test->test = (int (*)(int flags)) addr;
458 addr = (ulong) (test->init_f) + gd->reloc_off;
459 test->init_f = (int (*)(void)) addr;
463 addr = (ulong) (test->reloc) + gd->reloc_off;
464 test->reloc = (void (*)(void)) addr;
474 * Some tests (e.g. SYSMON) need the time when post_init_f started,
475 * but we cannot use get_timer() at this point.
477 * On PowerPC we implement it using the timebase register.
479 unsigned long post_time_ms (unsigned long base)
482 return (unsigned long)(get_ticks () / (get_tbclk () / CONFIG_SYS_HZ)) - base;
484 #warning "Not implemented yet"
485 return 0; /* Not implemented yet */