1 // SPDX-License-Identifier: GPL-2.0+
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
13 #ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
17 DECLARE_GLOBAL_DATA_PTR
;
19 #define POST_MAX_NUMBER 32
21 #define BOOTMODE_MAGIC 0xDEAD0000
28 for (i
= 0; i
< post_list_size
; i
++) {
29 struct post_test
*test
= post_list
+ i
;
31 if (test
->init_f
&& test
->init_f())
35 gd
->post_init_f_time
= post_time_ms(0);
36 if (!gd
->post_init_f_time
)
37 printf("%s: post_time_ms not implemented\n", __FILE__
);
43 * Supply a default implementation for post_hotkeys_pressed() for boards
44 * without hotkey support. We always return 0 here, so that the
45 * long-running tests won't be started.
47 * Boards with hotkey support can override this weak default function
48 * by defining one in their board specific code.
50 __weak
int post_hotkeys_pressed(void)
52 #ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
54 unsigned gpio
= CONFIG_SYS_POST_HOTKEYS_GPIO
;
56 ret
= gpio_request(gpio
, "hotkeys");
58 printf("POST: gpio hotkey request failed\n");
62 gpio_direction_input(gpio
);
63 ret
= gpio_get_value(gpio
);
69 return 0; /* No hotkeys supported */
72 void post_bootmode_init(void)
74 int bootmode
= post_bootmode_get(0);
77 if (post_hotkeys_pressed() && !(bootmode
& POST_POWERTEST
))
78 newword
= BOOTMODE_MAGIC
| POST_SLOWTEST
;
79 else if (bootmode
== 0)
80 newword
= BOOTMODE_MAGIC
| POST_POWERON
;
81 else if (bootmode
== POST_POWERON
|| bootmode
== POST_SLOWTEST
)
82 newword
= BOOTMODE_MAGIC
| POST_NORMAL
;
85 newword
= post_word_load() & ~POST_COLDBOOT
;
88 /* We are booting after power-on */
89 newword
|= POST_COLDBOOT
;
91 post_word_store(newword
);
93 /* Reset activity record */
94 gd
->post_log_word
= 0;
98 int post_bootmode_get(unsigned int *last_test
)
100 unsigned long word
= post_word_load();
103 if ((word
& 0xFFFF0000) != BOOTMODE_MAGIC
)
106 bootmode
= word
& 0x7F;
108 if (last_test
&& (bootmode
& POST_POWERTEST
))
109 *last_test
= (word
>> 8) & 0xFF;
114 /* POST tests run before relocation only mark status bits .... */
115 static void post_log_mark_start(unsigned long testid
)
117 gd
->post_log_word
|= testid
;
120 static void post_log_mark_succ(unsigned long testid
)
122 gd
->post_log_res
|= testid
;
125 /* ... and the messages are output once we are relocated */
126 void post_output_backlog(void)
130 for (j
= 0; j
< post_list_size
; j
++) {
131 if (gd
->post_log_word
& (post_list
[j
].testid
)) {
132 post_log("POST %s ", post_list
[j
].cmd
);
133 if (gd
->post_log_res
& post_list
[j
].testid
)
134 post_log("PASSED\n");
136 post_log("FAILED\n");
137 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R
);
143 static void post_bootmode_test_on(unsigned int last_test
)
145 unsigned long word
= post_word_load();
147 word
|= POST_POWERTEST
;
149 word
|= (last_test
& 0xFF) << 8;
151 post_word_store(word
);
154 static void post_bootmode_test_off(void)
156 unsigned long word
= post_word_load();
158 word
&= ~POST_POWERTEST
;
160 post_word_store(word
);
163 #ifndef CONFIG_POST_SKIP_ENV_FLAGS
164 static void post_get_env_flags(int *test_flags
)
166 int flag
[] = { POST_POWERON
, POST_NORMAL
, POST_SLOWTEST
,
168 char *var
[] = { "post_poweron", "post_normal", "post_slowtest",
170 int varnum
= ARRAY_SIZE(var
);
171 char list
[128]; /* long enough for POST list */
177 for (i
= 0; i
< varnum
; i
++) {
178 if (env_get_f(var
[i
], list
, sizeof(list
)) <= 0)
181 for (j
= 0; j
< post_list_size
; j
++)
182 test_flags
[j
] &= ~flag
[i
];
187 while (*name
&& *name
== ' ')
192 while (*s
&& *s
!= ' ')
199 for (j
= 0; j
< post_list_size
; j
++) {
200 if (strcmp(post_list
[j
].cmd
, name
) == 0) {
201 test_flags
[j
] |= flag
[i
];
206 if (j
== post_list_size
)
207 printf("No such test: %s\n", name
);
215 static void post_get_flags(int *test_flags
)
219 for (j
= 0; j
< post_list_size
; j
++)
220 test_flags
[j
] = post_list
[j
].flags
;
222 #ifndef CONFIG_POST_SKIP_ENV_FLAGS
223 post_get_env_flags(test_flags
);
226 for (j
= 0; j
< post_list_size
; j
++)
227 if (test_flags
[j
] & POST_POWERON
)
228 test_flags
[j
] |= POST_SLOWTEST
;
231 __weak
void show_post_progress(unsigned int test_num
, int before
, int result
)
235 static int post_run_single(struct post_test
*test
,
236 int test_flags
, int flags
, unsigned int i
)
238 if ((flags
& test_flags
& POST_ALWAYS
) &&
239 (flags
& test_flags
& POST_MEM
)) {
242 if (!(flags
& POST_REBOOT
)) {
243 if ((test_flags
& POST_REBOOT
) &&
244 !(flags
& POST_MANUAL
)) {
245 post_bootmode_test_on(
246 (gd
->flags
& GD_FLG_POSTFAIL
) ?
247 POST_FAIL_SAVE
| i
: i
);
250 if (test_flags
& POST_PREREL
)
251 post_log_mark_start(test
->testid
);
253 post_log("POST %s ", test
->cmd
);
256 show_post_progress(i
, POST_BEFORE
, POST_FAILED
);
258 if (test_flags
& POST_PREREL
) {
259 if ((*test
->test
)(flags
) == 0) {
260 post_log_mark_succ(test
->testid
);
261 show_post_progress(i
, POST_AFTER
, POST_PASSED
);
263 show_post_progress(i
, POST_AFTER
, POST_FAILED
);
264 if (test_flags
& POST_CRITICAL
)
265 gd
->flags
|= GD_FLG_POSTFAIL
;
266 if (test_flags
& POST_STOP
)
267 gd
->flags
|= GD_FLG_POSTSTOP
;
270 if ((*test
->test
)(flags
) != 0) {
271 post_log("FAILED\n");
272 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R
);
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
;
279 post_log("PASSED\n");
280 show_post_progress(i
, POST_AFTER
, POST_PASSED
);
284 if ((test_flags
& POST_REBOOT
) && !(flags
& POST_MANUAL
))
285 post_bootmode_test_off();
293 int post_run(char *name
, int flags
)
296 int test_flags
[POST_MAX_NUMBER
];
298 post_get_flags(test_flags
);
303 if (gd
->flags
& GD_FLG_POSTSTOP
)
306 if (post_bootmode_get(&last
) & POST_POWERTEST
) {
307 if (last
& POST_FAIL_SAVE
) {
308 last
&= ~POST_FAIL_SAVE
;
309 gd
->flags
|= GD_FLG_POSTFAIL
;
311 if (last
< post_list_size
&&
312 (flags
& test_flags
[last
] & POST_ALWAYS
) &&
313 (flags
& test_flags
[last
] & POST_MEM
)) {
315 post_run_single(post_list
+ last
,
317 flags
| POST_REBOOT
, last
);
319 for (i
= last
+ 1; i
< post_list_size
; i
++) {
320 if (gd
->flags
& GD_FLG_POSTSTOP
)
322 post_run_single(post_list
+ i
,
328 for (i
= 0; i
< post_list_size
; i
++) {
329 if (gd
->flags
& GD_FLG_POSTSTOP
)
331 post_run_single(post_list
+ i
,
339 for (i
= 0; i
< post_list_size
; i
++) {
340 if (strcmp(post_list
[i
].cmd
, name
) == 0)
344 if (i
< post_list_size
) {
346 return post_run_single(post_list
+ i
,
355 static int post_info_single(struct post_test
*test
, int full
)
357 if (test
->flags
& POST_MANUAL
) {
360 " %s\n", test
->cmd
, test
->name
, test
->desc
);
362 printf(" %-15s - %s\n", test
->cmd
, test
->name
);
370 int post_info(char *name
)
375 for (i
= 0; i
< post_list_size
; i
++)
376 post_info_single(post_list
+ i
, 0);
380 for (i
= 0; i
< post_list_size
; i
++) {
381 if (strcmp(post_list
[i
].cmd
, name
) == 0)
385 if (i
< post_list_size
)
386 return post_info_single(post_list
+ i
, 1);
392 int post_log(char *format
, ...)
395 char printbuffer
[CONFIG_SYS_PBSIZE
];
397 va_start(args
, format
);
399 /* For this to work, printbuffer must be larger than
400 * anything we ever want to print.
402 vsprintf(printbuffer
, format
, args
);
405 /* Send to the stdout file */
411 #ifdef CONFIG_NEEDS_MANUAL_RELOC
412 void post_reloc(void)
417 * We have to relocate the test table manually
419 for (i
= 0; i
< post_list_size
; i
++) {
421 struct post_test
*test
= post_list
+ i
;
424 addr
= (ulong
)(test
->name
) + gd
->reloc_off
;
425 test
->name
= (char *)addr
;
429 addr
= (ulong
)(test
->cmd
) + gd
->reloc_off
;
430 test
->cmd
= (char *)addr
;
434 addr
= (ulong
)(test
->desc
) + gd
->reloc_off
;
435 test
->desc
= (char *)addr
;
439 addr
= (ulong
)(test
->test
) + gd
->reloc_off
;
440 test
->test
= (int (*)(int flags
)) addr
;
444 addr
= (ulong
)(test
->init_f
) + gd
->reloc_off
;
445 test
->init_f
= (int (*)(void)) addr
;
449 addr
= (ulong
)(test
->reloc
) + gd
->reloc_off
;
450 test
->reloc
= (void (*)(void)) addr
;
460 * Some tests (e.g. SYSMON) need the time when post_init_f started,
461 * but we cannot use get_timer() at this point.
463 * On PowerPC we implement it using the timebase register.
465 unsigned long post_time_ms(unsigned long base
)
467 #if defined(CONFIG_PPC) || defined(CONFIG_ARM)
468 return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ
)
471 #warning "Not implemented yet"
472 return 0; /* Not implemented yet */