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;
124 gd
->post_log_res
= 0;
127 int post_bootmode_get (unsigned int *last_test
)
129 unsigned long word
= post_word_load ();
132 if ((word
& 0xFFFF0000) != BOOTMODE_MAGIC
) {
136 bootmode
= word
& 0x7F;
138 if (last_test
&& (bootmode
& POST_POWERTEST
)) {
139 *last_test
= (word
>> 8) & 0xFF;
145 /* POST tests run before relocation only mark status bits .... */
146 static void post_log_mark_start ( unsigned long testid
)
148 gd
->post_log_word
|= testid
;
151 static void post_log_mark_succ ( unsigned long testid
)
153 gd
->post_log_res
|= testid
;
156 /* ... and the messages are output once we are relocated */
157 void post_output_backlog ( void )
161 for (j
= 0; j
< post_list_size
; j
++) {
162 if (gd
->post_log_word
& (post_list
[j
].testid
)) {
163 post_log ("POST %s ", post_list
[j
].cmd
);
164 if (gd
->post_log_res
& post_list
[j
].testid
)
165 post_log ("PASSED\n");
167 post_log ("FAILED\n");
168 show_boot_progress (-31);
174 static void post_bootmode_test_on (unsigned int last_test
)
176 unsigned long word
= post_word_load ();
178 word
|= POST_POWERTEST
;
180 word
|= (last_test
& 0xFF) << 8;
182 post_word_store (word
);
185 static void post_bootmode_test_off (void)
187 unsigned long word
= post_word_load ();
189 word
&= ~POST_POWERTEST
;
191 post_word_store (word
);
194 static void post_get_flags (int *test_flags
)
196 int flag
[] = { POST_POWERON
, POST_NORMAL
, POST_SLOWTEST
,
198 char *var
[] = { "post_poweron", "post_normal", "post_slowtest",
200 int varnum
= ARRAY_SIZE(var
);
201 char list
[128]; /* long enough for POST list */
207 for (j
= 0; j
< post_list_size
; j
++) {
208 test_flags
[j
] = post_list
[j
].flags
;
211 for (i
= 0; i
< varnum
; i
++) {
212 if (getenv_f(var
[i
], list
, sizeof (list
)) <= 0)
215 for (j
= 0; j
< post_list_size
; j
++) {
216 test_flags
[j
] &= ~flag
[i
];
222 while (*name
&& *name
== ' ')
227 while (*s
&& *s
!= ' ')
234 for (j
= 0; j
< post_list_size
; j
++) {
235 if (strcmp (post_list
[j
].cmd
, name
) == 0) {
236 test_flags
[j
] |= flag
[i
];
241 if (j
== post_list_size
) {
242 printf ("No such test: %s\n", name
);
249 for (j
= 0; j
< post_list_size
; j
++) {
250 if (test_flags
[j
] & POST_POWERON
) {
251 test_flags
[j
] |= POST_SLOWTEST
;
256 void __show_post_progress (unsigned int test_num
, int before
, int result
)
259 void show_post_progress (unsigned int, int, int)
260 __attribute__((weak
, alias("__show_post_progress")));
262 static int post_run_single (struct post_test
*test
,
263 int test_flags
, int flags
, unsigned int i
)
265 if ((flags
& test_flags
& POST_ALWAYS
) &&
266 (flags
& test_flags
& POST_MEM
)) {
269 if (!(flags
& POST_REBOOT
)) {
270 if ((test_flags
& POST_REBOOT
) && !(flags
& POST_MANUAL
)) {
271 post_bootmode_test_on (
272 (gd
->flags
& GD_FLG_POSTFAIL
) ?
273 POST_FAIL_SAVE
| i
: i
);
276 if (test_flags
& POST_PREREL
)
277 post_log_mark_start ( test
->testid
);
279 post_log ("POST %s ", test
->cmd
);
282 show_post_progress(i
, POST_BEFORE
, POST_FAILED
);
284 if (test_flags
& POST_PREREL
) {
285 if ((*test
->test
) (flags
) == 0) {
286 post_log_mark_succ ( test
->testid
);
287 show_post_progress(i
, POST_AFTER
, POST_PASSED
);
290 show_post_progress(i
, POST_AFTER
, POST_FAILED
);
291 if (test_flags
& POST_CRITICAL
)
292 gd
->flags
|= GD_FLG_POSTFAIL
;
293 if (test_flags
& POST_STOP
)
294 gd
->flags
|= GD_FLG_POSTSTOP
;
297 if ((*test
->test
)(flags
) != 0) {
298 post_log("FAILED\n");
299 show_boot_progress(-32);
300 show_post_progress(i
, POST_AFTER
, POST_FAILED
);
301 if (test_flags
& POST_CRITICAL
)
302 gd
->flags
|= GD_FLG_POSTFAIL
;
303 if (test_flags
& POST_STOP
)
304 gd
->flags
|= GD_FLG_POSTSTOP
;
306 post_log("PASSED\n");
307 show_post_progress(i
, POST_AFTER
, POST_PASSED
);
311 if ((test_flags
& POST_REBOOT
) && !(flags
& POST_MANUAL
)) {
312 post_bootmode_test_off ();
321 int post_run (char *name
, int flags
)
324 int test_flags
[POST_MAX_NUMBER
];
326 post_get_flags (test_flags
);
331 if (gd
->flags
& GD_FLG_POSTSTOP
)
334 if (post_bootmode_get (&last
) & POST_POWERTEST
) {
335 if (last
& POST_FAIL_SAVE
) {
336 last
&= ~POST_FAIL_SAVE
;
337 gd
->flags
|= GD_FLG_POSTFAIL
;
339 if (last
< post_list_size
&&
340 (flags
& test_flags
[last
] & POST_ALWAYS
) &&
341 (flags
& test_flags
[last
] & POST_MEM
)) {
343 post_run_single (post_list
+ last
,
345 flags
| POST_REBOOT
, last
);
347 for (i
= last
+ 1; i
< post_list_size
; i
++) {
348 if (gd
->flags
& GD_FLG_POSTSTOP
)
350 post_run_single (post_list
+ i
,
356 for (i
= 0; i
< post_list_size
; i
++) {
357 if (gd
->flags
& GD_FLG_POSTSTOP
)
359 post_run_single (post_list
+ i
,
367 for (i
= 0; i
< post_list_size
; i
++) {
368 if (strcmp (post_list
[i
].cmd
, name
) == 0)
372 if (i
< post_list_size
) {
374 return post_run_single (post_list
+ i
,
383 static int post_info_single (struct post_test
*test
, int full
)
385 if (test
->flags
& POST_MANUAL
) {
388 " %s\n", test
->cmd
, test
->name
, test
->desc
);
390 printf (" %-15s - %s\n", test
->cmd
, test
->name
);
398 int post_info (char *name
)
403 for (i
= 0; i
< post_list_size
; i
++) {
404 post_info_single (post_list
+ i
, 0);
409 for (i
= 0; i
< post_list_size
; i
++) {
410 if (strcmp (post_list
[i
].cmd
, name
) == 0)
414 if (i
< post_list_size
) {
415 return post_info_single (post_list
+ i
, 1);
422 int post_log (char *format
, ...)
426 char printbuffer
[CONFIG_SYS_PBSIZE
];
428 va_start (args
, format
);
430 /* For this to work, printbuffer must be larger than
431 * anything we ever want to print.
433 i
= vsprintf (printbuffer
, format
, args
);
436 #ifdef CONFIG_LOGBUFFER
437 /* Send to the logbuffer */
438 logbuff_log (printbuffer
);
440 /* Send to the stdout file */
447 #ifdef CONFIG_NEEDS_MANUAL_RELOC
448 void post_reloc (void)
453 * We have to relocate the test table manually
455 for (i
= 0; i
< post_list_size
; i
++) {
457 struct post_test
*test
= post_list
+ i
;
460 addr
= (ulong
) (test
->name
) + gd
->reloc_off
;
461 test
->name
= (char *) addr
;
465 addr
= (ulong
) (test
->cmd
) + gd
->reloc_off
;
466 test
->cmd
= (char *) addr
;
470 addr
= (ulong
) (test
->desc
) + gd
->reloc_off
;
471 test
->desc
= (char *) addr
;
475 addr
= (ulong
) (test
->test
) + gd
->reloc_off
;
476 test
->test
= (int (*)(int flags
)) addr
;
480 addr
= (ulong
) (test
->init_f
) + gd
->reloc_off
;
481 test
->init_f
= (int (*)(void)) addr
;
485 addr
= (ulong
) (test
->reloc
) + gd
->reloc_off
;
486 test
->reloc
= (void (*)(void)) addr
;
496 * Some tests (e.g. SYSMON) need the time when post_init_f started,
497 * but we cannot use get_timer() at this point.
499 * On PowerPC we implement it using the timebase register.
501 unsigned long post_time_ms (unsigned long base
)
504 return (unsigned long)(get_ticks () / (get_tbclk () / CONFIG_SYS_HZ
)) - base
;
506 #warning "Not implemented yet"
507 return 0; /* Not implemented yet */