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>
30 #ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
34 #ifdef CONFIG_LOGBUFFER
38 DECLARE_GLOBAL_DATA_PTR
;
40 #define POST_MAX_NUMBER 32
42 #define BOOTMODE_MAGIC 0xDEAD0000
49 for (i
= 0; i
< post_list_size
; i
++) {
50 struct post_test
*test
= post_list
+ i
;
52 if (test
->init_f
&& test
->init_f())
56 gd
->post_init_f_time
= post_time_ms(0);
57 if (!gd
->post_init_f_time
)
58 printf("%s: post_time_ms not implemented\n", __FILE__
);
64 * Supply a default implementation for post_hotkeys_pressed() for boards
65 * without hotkey support. We always return 0 here, so that the
66 * long-running tests won't be started.
68 * Boards with hotkey support can override this weak default function
69 * by defining one in their board specific code.
71 int __post_hotkeys_pressed(void)
73 #ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
75 unsigned gpio
= CONFIG_SYS_POST_HOTKEYS_GPIO
;
77 ret
= gpio_request(gpio
, "hotkeys");
79 printf("POST: gpio hotkey request failed\n");
83 gpio_direction_input(gpio
);
84 ret
= gpio_get_value(gpio
);
90 return 0; /* No hotkeys supported */
92 int post_hotkeys_pressed(void)
93 __attribute__((weak
, alias("__post_hotkeys_pressed")));
96 void post_bootmode_init(void)
98 int bootmode
= post_bootmode_get(0);
101 if (post_hotkeys_pressed() && !(bootmode
& POST_POWERTEST
))
102 newword
= BOOTMODE_MAGIC
| POST_SLOWTEST
;
103 else if (bootmode
== 0)
104 newword
= BOOTMODE_MAGIC
| POST_POWERON
;
105 else if (bootmode
== POST_POWERON
|| bootmode
== POST_SLOWTEST
)
106 newword
= BOOTMODE_MAGIC
| POST_NORMAL
;
109 newword
= post_word_load() & ~POST_COLDBOOT
;
112 /* We are booting after power-on */
113 newword
|= POST_COLDBOOT
;
115 post_word_store(newword
);
117 /* Reset activity record */
118 gd
->post_log_word
= 0;
119 gd
->post_log_res
= 0;
122 int post_bootmode_get(unsigned int *last_test
)
124 unsigned long word
= post_word_load();
127 if ((word
& 0xFFFF0000) != BOOTMODE_MAGIC
)
130 bootmode
= word
& 0x7F;
132 if (last_test
&& (bootmode
& POST_POWERTEST
))
133 *last_test
= (word
>> 8) & 0xFF;
138 /* POST tests run before relocation only mark status bits .... */
139 static void post_log_mark_start(unsigned long testid
)
141 gd
->post_log_word
|= testid
;
144 static void post_log_mark_succ(unsigned long testid
)
146 gd
->post_log_res
|= testid
;
149 /* ... and the messages are output once we are relocated */
150 void post_output_backlog(void)
154 for (j
= 0; j
< post_list_size
; j
++) {
155 if (gd
->post_log_word
& (post_list
[j
].testid
)) {
156 post_log("POST %s ", post_list
[j
].cmd
);
157 if (gd
->post_log_res
& post_list
[j
].testid
)
158 post_log("PASSED\n");
160 post_log("FAILED\n");
161 show_boot_progress(-31);
167 static void post_bootmode_test_on(unsigned int last_test
)
169 unsigned long word
= post_word_load();
171 word
|= POST_POWERTEST
;
173 word
|= (last_test
& 0xFF) << 8;
175 post_word_store(word
);
178 static void post_bootmode_test_off(void)
180 unsigned long word
= post_word_load();
182 word
&= ~POST_POWERTEST
;
184 post_word_store(word
);
187 #ifndef CONFIG_POST_SKIP_ENV_FLAGS
188 static void post_get_env_flags(int *test_flags
)
190 int flag
[] = { POST_POWERON
, POST_NORMAL
, POST_SLOWTEST
,
192 char *var
[] = { "post_poweron", "post_normal", "post_slowtest",
194 int varnum
= ARRAY_SIZE(var
);
195 char list
[128]; /* long enough for POST list */
201 for (i
= 0; i
< varnum
; i
++) {
202 if (getenv_f(var
[i
], list
, sizeof(list
)) <= 0)
205 for (j
= 0; j
< post_list_size
; j
++)
206 test_flags
[j
] &= ~flag
[i
];
211 while (*name
&& *name
== ' ')
216 while (*s
&& *s
!= ' ')
223 for (j
= 0; j
< post_list_size
; j
++) {
224 if (strcmp(post_list
[j
].cmd
, name
) == 0) {
225 test_flags
[j
] |= flag
[i
];
230 if (j
== post_list_size
)
231 printf("No such test: %s\n", name
);
239 static void post_get_flags(int *test_flags
)
243 for (j
= 0; j
< post_list_size
; j
++)
244 test_flags
[j
] = post_list
[j
].flags
;
246 #ifndef CONFIG_POST_SKIP_ENV_FLAGS
247 post_get_env_flags(test_flags
);
250 for (j
= 0; j
< post_list_size
; j
++)
251 if (test_flags
[j
] & POST_POWERON
)
252 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
) &&
270 !(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
);
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();
319 int post_run(char *name
, int flags
)
322 int test_flags
[POST_MAX_NUMBER
];
324 post_get_flags(test_flags
);
329 if (gd
->flags
& GD_FLG_POSTSTOP
)
332 if (post_bootmode_get(&last
) & POST_POWERTEST
) {
333 if (last
& POST_FAIL_SAVE
) {
334 last
&= ~POST_FAIL_SAVE
;
335 gd
->flags
|= GD_FLG_POSTFAIL
;
337 if (last
< post_list_size
&&
338 (flags
& test_flags
[last
] & POST_ALWAYS
) &&
339 (flags
& test_flags
[last
] & POST_MEM
)) {
341 post_run_single(post_list
+ last
,
343 flags
| POST_REBOOT
, last
);
345 for (i
= last
+ 1; i
< post_list_size
; i
++) {
346 if (gd
->flags
& GD_FLG_POSTSTOP
)
348 post_run_single(post_list
+ i
,
354 for (i
= 0; i
< post_list_size
; i
++) {
355 if (gd
->flags
& GD_FLG_POSTSTOP
)
357 post_run_single(post_list
+ i
,
365 for (i
= 0; i
< post_list_size
; i
++) {
366 if (strcmp(post_list
[i
].cmd
, name
) == 0)
370 if (i
< post_list_size
) {
372 return post_run_single(post_list
+ i
,
381 static int post_info_single(struct post_test
*test
, int full
)
383 if (test
->flags
& POST_MANUAL
) {
386 " %s\n", test
->cmd
, test
->name
, test
->desc
);
388 printf(" %-15s - %s\n", test
->cmd
, test
->name
);
396 int post_info(char *name
)
401 for (i
= 0; i
< post_list_size
; i
++)
402 post_info_single(post_list
+ i
, 0);
406 for (i
= 0; i
< post_list_size
; i
++) {
407 if (strcmp(post_list
[i
].cmd
, name
) == 0)
411 if (i
< post_list_size
)
412 return post_info_single(post_list
+ i
, 1);
418 int post_log(char *format
, ...)
421 char printbuffer
[CONFIG_SYS_PBSIZE
];
423 va_start(args
, format
);
425 /* For this to work, printbuffer must be larger than
426 * anything we ever want to print.
428 vsprintf(printbuffer
, format
, args
);
431 #ifdef CONFIG_LOGBUFFER
432 /* Send to the logbuffer */
433 logbuff_log(printbuffer
);
435 /* Send to the stdout file */
442 #ifdef CONFIG_NEEDS_MANUAL_RELOC
443 void post_reloc(void)
448 * We have to relocate the test table manually
450 for (i
= 0; i
< post_list_size
; i
++) {
452 struct post_test
*test
= post_list
+ i
;
455 addr
= (ulong
)(test
->name
) + gd
->reloc_off
;
456 test
->name
= (char *)addr
;
460 addr
= (ulong
)(test
->cmd
) + gd
->reloc_off
;
461 test
->cmd
= (char *)addr
;
465 addr
= (ulong
)(test
->desc
) + gd
->reloc_off
;
466 test
->desc
= (char *)addr
;
470 addr
= (ulong
)(test
->test
) + gd
->reloc_off
;
471 test
->test
= (int (*)(int flags
)) addr
;
475 addr
= (ulong
)(test
->init_f
) + gd
->reloc_off
;
476 test
->init_f
= (int (*)(void)) addr
;
480 addr
= (ulong
)(test
->reloc
) + gd
->reloc_off
;
481 test
->reloc
= (void (*)(void)) addr
;
491 * Some tests (e.g. SYSMON) need the time when post_init_f started,
492 * but we cannot use get_timer() at this point.
494 * On PowerPC we implement it using the timebase register.
496 unsigned long post_time_ms(unsigned long base
)
498 #if defined(CONFIG_PPC) || defined(CONFIG_ARM) && !defined(CONFIG_KIRKWOOD)
499 return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ
)
502 #warning "Not implemented yet"
503 return 0; /* Not implemented yet */