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_SYS_POST_HOTKEYS_GPIO
33 #ifdef CONFIG_LOGBUFFER
37 DECLARE_GLOBAL_DATA_PTR;
39 #define POST_MAX_NUMBER 32
41 #define BOOTMODE_MAGIC 0xDEAD0000
43 int post_init_f (void)
48 for (i = 0; i < post_list_size; i++) {
49 struct post_test *test = post_list + i;
51 if (test->init_f && test->init_f()) {
56 gd->post_init_f_time = post_time_ms(0);
57 if (!gd->post_init_f_time)
59 printf("post/post.c: post_time_ms seems not to be implemented\n");
66 * Supply a default implementation for post_hotkeys_pressed() for boards
67 * without hotkey support. We always return 0 here, so that the
68 * long-running tests won't be started.
70 * Boards with hotkey support can override this weak default function
71 * by defining one in their board specific code.
73 int __post_hotkeys_pressed(void)
75 #ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
77 unsigned gpio = CONFIG_SYS_POST_HOTKEYS_GPIO;
79 ret = gpio_request(gpio, "hotkeys");
81 printf("POST: gpio hotkey request failed\n");
85 gpio_direction_input(gpio);
86 ret = gpio_get_value(gpio);
92 return 0; /* No hotkeys supported */
94 int post_hotkeys_pressed(void)
95 __attribute__((weak, alias("__post_hotkeys_pressed")));
98 void post_bootmode_init (void)
100 int bootmode = post_bootmode_get (0);
103 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST)) {
104 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
105 } else if (bootmode == 0) {
106 newword = BOOTMODE_MAGIC | POST_POWERON;
107 } else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST) {
108 newword = BOOTMODE_MAGIC | POST_NORMAL;
111 newword = post_word_load () & ~POST_COLDBOOT;
116 /* We are booting after power-on */
117 newword |= POST_COLDBOOT;
120 post_word_store (newword);
122 /* Reset activity record */
123 gd->post_log_word = 0;
126 int post_bootmode_get (unsigned int *last_test)
128 unsigned long word = post_word_load ();
131 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC) {
135 bootmode = word & 0x7F;
137 if (last_test && (bootmode & POST_POWERTEST)) {
138 *last_test = (word >> 8) & 0xFF;
144 /* POST tests run before relocation only mark status bits .... */
145 static void post_log_mark_start ( unsigned long testid )
147 gd->post_log_word |= (testid)<<16;
150 static void post_log_mark_succ ( unsigned long testid )
152 gd->post_log_word |= testid;
155 /* ... and the messages are output once we are relocated */
156 void post_output_backlog ( void )
160 for (j = 0; j < post_list_size; j++) {
161 if (gd->post_log_word & (post_list[j].testid<<16)) {
162 post_log ("POST %s ", post_list[j].cmd);
163 if (gd->post_log_word & post_list[j].testid)
164 post_log ("PASSED\n");
166 post_log ("FAILED\n");
167 show_boot_progress (-31);
173 static void post_bootmode_test_on (unsigned int last_test)
175 unsigned long word = post_word_load ();
177 word |= POST_POWERTEST;
179 word |= (last_test & 0xFF) << 8;
181 post_word_store (word);
184 static void post_bootmode_test_off (void)
186 unsigned long word = post_word_load ();
188 word &= ~POST_POWERTEST;
190 post_word_store (word);
193 static void post_get_flags (int *test_flags)
195 int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST,
197 char *var[] = { "post_poweron", "post_normal", "post_slowtest",
199 int varnum = ARRAY_SIZE(var);
200 char list[128]; /* long enough for POST list */
206 for (j = 0; j < post_list_size; j++) {
207 test_flags[j] = post_list[j].flags;
210 for (i = 0; i < varnum; i++) {
211 if (getenv_f(var[i], list, sizeof (list)) <= 0)
214 for (j = 0; j < post_list_size; j++) {
215 test_flags[j] &= ~flag[i];
221 while (*name && *name == ' ')
226 while (*s && *s != ' ')
233 for (j = 0; j < post_list_size; j++) {
234 if (strcmp (post_list[j].cmd, name) == 0) {
235 test_flags[j] |= flag[i];
240 if (j == post_list_size) {
241 printf ("No such test: %s\n", name);
248 for (j = 0; j < post_list_size; j++) {
249 if (test_flags[j] & POST_POWERON) {
250 test_flags[j] |= POST_SLOWTEST;
255 void __show_post_progress (unsigned int test_num, int before, int result)
258 void show_post_progress (unsigned int, int, int)
259 __attribute__((weak, alias("__show_post_progress")));
261 static int post_run_single (struct post_test *test,
262 int test_flags, int flags, unsigned int i)
264 if ((flags & test_flags & POST_ALWAYS) &&
265 (flags & test_flags & POST_MEM)) {
268 if (!(flags & POST_REBOOT)) {
269 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
270 post_bootmode_test_on (
271 (gd->flags & GD_FLG_POSTFAIL) ?
272 POST_FAIL_SAVE | i : i);
275 if (test_flags & POST_PREREL)
276 post_log_mark_start ( test->testid );
278 post_log ("POST %s ", test->cmd);
281 show_post_progress(i, POST_BEFORE, POST_FAILED);
283 if (test_flags & POST_PREREL) {
284 if ((*test->test) (flags) == 0) {
285 post_log_mark_succ ( test->testid );
286 show_post_progress(i, POST_AFTER, POST_PASSED);
289 show_post_progress(i, POST_AFTER, POST_FAILED);
290 if (test_flags & POST_CRITICAL)
291 gd->flags |= GD_FLG_POSTFAIL;
292 if (test_flags & POST_STOP)
293 gd->flags |= GD_FLG_POSTSTOP;
296 if ((*test->test)(flags) != 0) {
297 post_log("FAILED\n");
298 show_boot_progress(-32);
299 show_post_progress(i, POST_AFTER, POST_FAILED);
300 if (test_flags & POST_CRITICAL)
301 gd->flags |= GD_FLG_POSTFAIL;
302 if (test_flags & POST_STOP)
303 gd->flags |= GD_FLG_POSTSTOP;
305 post_log("PASSED\n");
306 show_post_progress(i, POST_AFTER, POST_PASSED);
310 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
311 post_bootmode_test_off ();
320 int post_run (char *name, int flags)
323 int test_flags[POST_MAX_NUMBER];
325 post_get_flags (test_flags);
330 if (gd->flags & GD_FLG_POSTSTOP)
333 if (post_bootmode_get (&last) & POST_POWERTEST) {
334 if (last & POST_FAIL_SAVE) {
335 last &= ~POST_FAIL_SAVE;
336 gd->flags |= GD_FLG_POSTFAIL;
338 if (last < post_list_size &&
339 (flags & test_flags[last] & POST_ALWAYS) &&
340 (flags & test_flags[last] & POST_MEM)) {
342 post_run_single (post_list + last,
344 flags | POST_REBOOT, last);
346 for (i = last + 1; i < post_list_size; i++) {
347 if (gd->flags & GD_FLG_POSTSTOP)
349 post_run_single (post_list + i,
355 for (i = 0; i < post_list_size; i++) {
356 if (gd->flags & GD_FLG_POSTSTOP)
358 post_run_single (post_list + i,
366 for (i = 0; i < post_list_size; i++) {
367 if (strcmp (post_list[i].cmd, name) == 0)
371 if (i < post_list_size) {
373 return post_run_single (post_list + i,
382 static int post_info_single (struct post_test *test, int full)
384 if (test->flags & POST_MANUAL) {
387 " %s\n", test->cmd, test->name, test->desc);
389 printf (" %-15s - %s\n", test->cmd, test->name);
397 int post_info (char *name)
402 for (i = 0; i < post_list_size; i++) {
403 post_info_single (post_list + i, 0);
408 for (i = 0; i < post_list_size; i++) {
409 if (strcmp (post_list[i].cmd, name) == 0)
413 if (i < post_list_size) {
414 return post_info_single (post_list + i, 1);
421 int post_log (char *format, ...)
425 char printbuffer[CONFIG_SYS_PBSIZE];
427 va_start (args, format);
429 /* For this to work, printbuffer must be larger than
430 * anything we ever want to print.
432 i = vsprintf (printbuffer, format, args);
435 #ifdef CONFIG_LOGBUFFER
436 /* Send to the logbuffer */
437 logbuff_log (printbuffer);
439 /* Send to the stdout file */
446 #ifdef CONFIG_NEEDS_MANUAL_RELOC
447 void post_reloc (void)
452 * We have to relocate the test table manually
454 for (i = 0; i < post_list_size; i++) {
456 struct post_test *test = post_list + i;
459 addr = (ulong) (test->name) + gd->reloc_off;
460 test->name = (char *) addr;
464 addr = (ulong) (test->cmd) + gd->reloc_off;
465 test->cmd = (char *) addr;
469 addr = (ulong) (test->desc) + gd->reloc_off;
470 test->desc = (char *) addr;
474 addr = (ulong) (test->test) + gd->reloc_off;
475 test->test = (int (*)(int flags)) addr;
479 addr = (ulong) (test->init_f) + gd->reloc_off;
480 test->init_f = (int (*)(void)) addr;
484 addr = (ulong) (test->reloc) + gd->reloc_off;
485 test->reloc = (void (*)(void)) addr;
495 * Some tests (e.g. SYSMON) need the time when post_init_f started,
496 * but we cannot use get_timer() at this point.
498 * On PowerPC we implement it using the timebase register.
500 unsigned long post_time_ms (unsigned long base)
503 return (unsigned long)(get_ticks () / (get_tbclk () / CONFIG_SYS_HZ)) - base;
505 #warning "Not implemented yet"
506 return 0; /* Not implemented yet */