3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
14 #ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
18 #ifdef CONFIG_LOGBUFFER
22 DECLARE_GLOBAL_DATA_PTR
;
24 #define POST_MAX_NUMBER 32
26 #define BOOTMODE_MAGIC 0xDEAD0000
33 for (i
= 0; i
< post_list_size
; i
++) {
34 struct post_test
*test
= post_list
+ i
;
36 if (test
->init_f
&& test
->init_f())
40 gd
->post_init_f_time
= post_time_ms(0);
41 if (!gd
->post_init_f_time
)
42 printf("%s: post_time_ms not implemented\n", __FILE__
);
48 * Supply a default implementation for post_hotkeys_pressed() for boards
49 * without hotkey support. We always return 0 here, so that the
50 * long-running tests won't be started.
52 * Boards with hotkey support can override this weak default function
53 * by defining one in their board specific code.
55 int __post_hotkeys_pressed(void)
57 #ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
59 unsigned gpio
= CONFIG_SYS_POST_HOTKEYS_GPIO
;
61 ret
= gpio_request(gpio
, "hotkeys");
63 printf("POST: gpio hotkey request failed\n");
67 gpio_direction_input(gpio
);
68 ret
= gpio_get_value(gpio
);
74 return 0; /* No hotkeys supported */
76 int post_hotkeys_pressed(void)
77 __attribute__((weak
, alias("__post_hotkeys_pressed")));
80 void post_bootmode_init(void)
82 int bootmode
= post_bootmode_get(0);
85 if (post_hotkeys_pressed() && !(bootmode
& POST_POWERTEST
))
86 newword
= BOOTMODE_MAGIC
| POST_SLOWTEST
;
87 else if (bootmode
== 0)
88 newword
= BOOTMODE_MAGIC
| POST_POWERON
;
89 else if (bootmode
== POST_POWERON
|| bootmode
== POST_SLOWTEST
)
90 newword
= BOOTMODE_MAGIC
| POST_NORMAL
;
93 newword
= post_word_load() & ~POST_COLDBOOT
;
96 /* We are booting after power-on */
97 newword
|= POST_COLDBOOT
;
99 post_word_store(newword
);
101 /* Reset activity record */
102 gd
->post_log_word
= 0;
103 gd
->post_log_res
= 0;
106 int post_bootmode_get(unsigned int *last_test
)
108 unsigned long word
= post_word_load();
111 if ((word
& 0xFFFF0000) != BOOTMODE_MAGIC
)
114 bootmode
= word
& 0x7F;
116 if (last_test
&& (bootmode
& POST_POWERTEST
))
117 *last_test
= (word
>> 8) & 0xFF;
122 /* POST tests run before relocation only mark status bits .... */
123 static void post_log_mark_start(unsigned long testid
)
125 gd
->post_log_word
|= testid
;
128 static void post_log_mark_succ(unsigned long testid
)
130 gd
->post_log_res
|= testid
;
133 /* ... and the messages are output once we are relocated */
134 void post_output_backlog(void)
138 for (j
= 0; j
< post_list_size
; j
++) {
139 if (gd
->post_log_word
& (post_list
[j
].testid
)) {
140 post_log("POST %s ", post_list
[j
].cmd
);
141 if (gd
->post_log_res
& post_list
[j
].testid
)
142 post_log("PASSED\n");
144 post_log("FAILED\n");
145 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R
);
151 static void post_bootmode_test_on(unsigned int last_test
)
153 unsigned long word
= post_word_load();
155 word
|= POST_POWERTEST
;
157 word
|= (last_test
& 0xFF) << 8;
159 post_word_store(word
);
162 static void post_bootmode_test_off(void)
164 unsigned long word
= post_word_load();
166 word
&= ~POST_POWERTEST
;
168 post_word_store(word
);
171 #ifndef CONFIG_POST_SKIP_ENV_FLAGS
172 static void post_get_env_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
= ARRAY_SIZE(var
);
179 char list
[128]; /* long enough for POST list */
185 for (i
= 0; i
< varnum
; i
++) {
186 if (getenv_f(var
[i
], list
, sizeof(list
)) <= 0)
189 for (j
= 0; j
< post_list_size
; j
++)
190 test_flags
[j
] &= ~flag
[i
];
195 while (*name
&& *name
== ' ')
200 while (*s
&& *s
!= ' ')
207 for (j
= 0; j
< post_list_size
; j
++) {
208 if (strcmp(post_list
[j
].cmd
, name
) == 0) {
209 test_flags
[j
] |= flag
[i
];
214 if (j
== post_list_size
)
215 printf("No such test: %s\n", name
);
223 static void post_get_flags(int *test_flags
)
227 for (j
= 0; j
< post_list_size
; j
++)
228 test_flags
[j
] = post_list
[j
].flags
;
230 #ifndef CONFIG_POST_SKIP_ENV_FLAGS
231 post_get_env_flags(test_flags
);
234 for (j
= 0; j
< post_list_size
; j
++)
235 if (test_flags
[j
] & POST_POWERON
)
236 test_flags
[j
] |= POST_SLOWTEST
;
239 void __show_post_progress(unsigned int test_num
, int before
, int result
)
242 void show_post_progress(unsigned int, int, int)
243 __attribute__((weak
, alias("__show_post_progress")));
245 static int post_run_single(struct post_test
*test
,
246 int test_flags
, int flags
, unsigned int i
)
248 if ((flags
& test_flags
& POST_ALWAYS
) &&
249 (flags
& test_flags
& POST_MEM
)) {
252 if (!(flags
& POST_REBOOT
)) {
253 if ((test_flags
& POST_REBOOT
) &&
254 !(flags
& POST_MANUAL
)) {
255 post_bootmode_test_on(
256 (gd
->flags
& GD_FLG_POSTFAIL
) ?
257 POST_FAIL_SAVE
| i
: i
);
260 if (test_flags
& POST_PREREL
)
261 post_log_mark_start(test
->testid
);
263 post_log("POST %s ", test
->cmd
);
266 show_post_progress(i
, POST_BEFORE
, POST_FAILED
);
268 if (test_flags
& POST_PREREL
) {
269 if ((*test
->test
)(flags
) == 0) {
270 post_log_mark_succ(test
->testid
);
271 show_post_progress(i
, POST_AFTER
, POST_PASSED
);
273 show_post_progress(i
, POST_AFTER
, POST_FAILED
);
274 if (test_flags
& POST_CRITICAL
)
275 gd
->flags
|= GD_FLG_POSTFAIL
;
276 if (test_flags
& POST_STOP
)
277 gd
->flags
|= GD_FLG_POSTSTOP
;
280 if ((*test
->test
)(flags
) != 0) {
281 post_log("FAILED\n");
282 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R
);
283 show_post_progress(i
, POST_AFTER
, POST_FAILED
);
284 if (test_flags
& POST_CRITICAL
)
285 gd
->flags
|= GD_FLG_POSTFAIL
;
286 if (test_flags
& POST_STOP
)
287 gd
->flags
|= GD_FLG_POSTSTOP
;
289 post_log("PASSED\n");
290 show_post_progress(i
, POST_AFTER
, POST_PASSED
);
294 if ((test_flags
& POST_REBOOT
) && !(flags
& POST_MANUAL
))
295 post_bootmode_test_off();
303 int post_run(char *name
, int flags
)
306 int test_flags
[POST_MAX_NUMBER
];
308 post_get_flags(test_flags
);
313 if (gd
->flags
& GD_FLG_POSTSTOP
)
316 if (post_bootmode_get(&last
) & POST_POWERTEST
) {
317 if (last
& POST_FAIL_SAVE
) {
318 last
&= ~POST_FAIL_SAVE
;
319 gd
->flags
|= GD_FLG_POSTFAIL
;
321 if (last
< post_list_size
&&
322 (flags
& test_flags
[last
] & POST_ALWAYS
) &&
323 (flags
& test_flags
[last
] & POST_MEM
)) {
325 post_run_single(post_list
+ last
,
327 flags
| POST_REBOOT
, last
);
329 for (i
= last
+ 1; i
< post_list_size
; i
++) {
330 if (gd
->flags
& GD_FLG_POSTSTOP
)
332 post_run_single(post_list
+ i
,
338 for (i
= 0; i
< post_list_size
; i
++) {
339 if (gd
->flags
& GD_FLG_POSTSTOP
)
341 post_run_single(post_list
+ i
,
349 for (i
= 0; i
< post_list_size
; i
++) {
350 if (strcmp(post_list
[i
].cmd
, name
) == 0)
354 if (i
< post_list_size
) {
356 return post_run_single(post_list
+ i
,
365 static int post_info_single(struct post_test
*test
, int full
)
367 if (test
->flags
& POST_MANUAL
) {
370 " %s\n", test
->cmd
, test
->name
, test
->desc
);
372 printf(" %-15s - %s\n", test
->cmd
, test
->name
);
380 int post_info(char *name
)
385 for (i
= 0; i
< post_list_size
; i
++)
386 post_info_single(post_list
+ i
, 0);
390 for (i
= 0; i
< post_list_size
; i
++) {
391 if (strcmp(post_list
[i
].cmd
, name
) == 0)
395 if (i
< post_list_size
)
396 return post_info_single(post_list
+ i
, 1);
402 int post_log(char *format
, ...)
405 char printbuffer
[CONFIG_SYS_PBSIZE
];
407 va_start(args
, format
);
409 /* For this to work, printbuffer must be larger than
410 * anything we ever want to print.
412 vsprintf(printbuffer
, format
, args
);
415 #ifdef CONFIG_LOGBUFFER
416 /* Send to the logbuffer */
417 logbuff_log(printbuffer
);
419 /* Send to the stdout file */
426 #ifdef CONFIG_NEEDS_MANUAL_RELOC
427 void post_reloc(void)
432 * We have to relocate the test table manually
434 for (i
= 0; i
< post_list_size
; i
++) {
436 struct post_test
*test
= post_list
+ i
;
439 addr
= (ulong
)(test
->name
) + gd
->reloc_off
;
440 test
->name
= (char *)addr
;
444 addr
= (ulong
)(test
->cmd
) + gd
->reloc_off
;
445 test
->cmd
= (char *)addr
;
449 addr
= (ulong
)(test
->desc
) + gd
->reloc_off
;
450 test
->desc
= (char *)addr
;
454 addr
= (ulong
)(test
->test
) + gd
->reloc_off
;
455 test
->test
= (int (*)(int flags
)) addr
;
459 addr
= (ulong
)(test
->init_f
) + gd
->reloc_off
;
460 test
->init_f
= (int (*)(void)) addr
;
464 addr
= (ulong
)(test
->reloc
) + gd
->reloc_off
;
465 test
->reloc
= (void (*)(void)) addr
;
475 * Some tests (e.g. SYSMON) need the time when post_init_f started,
476 * but we cannot use get_timer() at this point.
478 * On PowerPC we implement it using the timebase register.
480 unsigned long post_time_ms(unsigned long base
)
482 #if defined(CONFIG_PPC) || defined(CONFIG_BLACKFIN) || defined(CONFIG_ARM)
483 return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ
)
486 #warning "Not implemented yet"
487 return 0; /* Not implemented yet */