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
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())
55 gd->post_init_f_time = post_time_ms(0);
56 if (!gd->post_init_f_time)
57 printf("%s: post_time_ms not implemented\n", __FILE__);
63 * Supply a default implementation for post_hotkeys_pressed() for boards
64 * without hotkey support. We always return 0 here, so that the
65 * long-running tests won't be started.
67 * Boards with hotkey support can override this weak default function
68 * by defining one in their board specific code.
70 int __post_hotkeys_pressed(void)
72 #ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
74 unsigned gpio = CONFIG_SYS_POST_HOTKEYS_GPIO;
76 ret = gpio_request(gpio, "hotkeys");
78 printf("POST: gpio hotkey request failed\n");
82 gpio_direction_input(gpio);
83 ret = gpio_get_value(gpio);
89 return 0; /* No hotkeys supported */
91 int post_hotkeys_pressed(void)
92 __attribute__((weak, alias("__post_hotkeys_pressed")));
95 void post_bootmode_init(void)
97 int bootmode = post_bootmode_get(0);
100 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST))
101 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
102 else if (bootmode == 0)
103 newword = BOOTMODE_MAGIC | POST_POWERON;
104 else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST)
105 newword = BOOTMODE_MAGIC | POST_NORMAL;
108 newword = post_word_load() & ~POST_COLDBOOT;
111 /* We are booting after power-on */
112 newword |= POST_COLDBOOT;
114 post_word_store(newword);
116 /* Reset activity record */
117 gd->post_log_word = 0;
118 gd->post_log_res = 0;
121 int post_bootmode_get(unsigned int *last_test)
123 unsigned long word = post_word_load();
126 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC)
129 bootmode = word & 0x7F;
131 if (last_test && (bootmode & POST_POWERTEST))
132 *last_test = (word >> 8) & 0xFF;
137 /* POST tests run before relocation only mark status bits .... */
138 static void post_log_mark_start(unsigned long testid)
140 gd->post_log_word |= testid;
143 static void post_log_mark_succ(unsigned long testid)
145 gd->post_log_res |= testid;
148 /* ... and the messages are output once we are relocated */
149 void post_output_backlog(void)
153 for (j = 0; j < post_list_size; j++) {
154 if (gd->post_log_word & (post_list[j].testid)) {
155 post_log("POST %s ", post_list[j].cmd);
156 if (gd->post_log_res & post_list[j].testid)
157 post_log("PASSED\n");
159 post_log("FAILED\n");
160 show_boot_progress(-31);
166 static void post_bootmode_test_on(unsigned int last_test)
168 unsigned long word = post_word_load();
170 word |= POST_POWERTEST;
172 word |= (last_test & 0xFF) << 8;
174 post_word_store(word);
177 static void post_bootmode_test_off(void)
179 unsigned long word = post_word_load();
181 word &= ~POST_POWERTEST;
183 post_word_store(word);
186 #ifndef CONFIG_POST_SKIP_ENV_FLAGS
187 static void post_get_env_flags(int *test_flags)
189 int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST,
191 char *var[] = { "post_poweron", "post_normal", "post_slowtest",
193 int varnum = ARRAY_SIZE(var);
194 char list[128]; /* long enough for POST list */
200 for (i = 0; i < varnum; i++) {
201 if (getenv_f(var[i], list, sizeof(list)) <= 0)
204 for (j = 0; j < post_list_size; j++)
205 test_flags[j] &= ~flag[i];
210 while (*name && *name == ' ')
215 while (*s && *s != ' ')
222 for (j = 0; j < post_list_size; j++) {
223 if (strcmp(post_list[j].cmd, name) == 0) {
224 test_flags[j] |= flag[i];
229 if (j == post_list_size)
230 printf("No such test: %s\n", name);
238 static void post_get_flags(int *test_flags)
242 for (j = 0; j < post_list_size; j++)
243 test_flags[j] = post_list[j].flags;
245 #ifndef CONFIG_POST_SKIP_ENV_FLAGS
246 post_get_env_flags(test_flags);
249 for (j = 0; j < post_list_size; j++)
250 if (test_flags[j] & POST_POWERON)
251 test_flags[j] |= POST_SLOWTEST;
254 void __show_post_progress(unsigned int test_num, int before, int result)
257 void show_post_progress(unsigned int, int, int)
258 __attribute__((weak, alias("__show_post_progress")));
260 static int post_run_single(struct post_test *test,
261 int test_flags, int flags, unsigned int i)
263 if ((flags & test_flags & POST_ALWAYS) &&
264 (flags & test_flags & POST_MEM)) {
267 if (!(flags & POST_REBOOT)) {
268 if ((test_flags & POST_REBOOT) &&
269 !(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);
288 show_post_progress(i, POST_AFTER, POST_FAILED);
289 if (test_flags & POST_CRITICAL)
290 gd->flags |= GD_FLG_POSTFAIL;
291 if (test_flags & POST_STOP)
292 gd->flags |= GD_FLG_POSTSTOP;
295 if ((*test->test)(flags) != 0) {
296 post_log("FAILED\n");
297 show_boot_progress(-32);
298 show_post_progress(i, POST_AFTER, POST_FAILED);
299 if (test_flags & POST_CRITICAL)
300 gd->flags |= GD_FLG_POSTFAIL;
301 if (test_flags & POST_STOP)
302 gd->flags |= GD_FLG_POSTSTOP;
304 post_log("PASSED\n");
305 show_post_progress(i, POST_AFTER, POST_PASSED);
309 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL))
310 post_bootmode_test_off();
318 int post_run(char *name, int flags)
321 int test_flags[POST_MAX_NUMBER];
323 post_get_flags(test_flags);
328 if (gd->flags & GD_FLG_POSTSTOP)
331 if (post_bootmode_get(&last) & POST_POWERTEST) {
332 if (last & POST_FAIL_SAVE) {
333 last &= ~POST_FAIL_SAVE;
334 gd->flags |= GD_FLG_POSTFAIL;
336 if (last < post_list_size &&
337 (flags & test_flags[last] & POST_ALWAYS) &&
338 (flags & test_flags[last] & POST_MEM)) {
340 post_run_single(post_list + last,
342 flags | POST_REBOOT, last);
344 for (i = last + 1; i < post_list_size; i++) {
345 if (gd->flags & GD_FLG_POSTSTOP)
347 post_run_single(post_list + i,
353 for (i = 0; i < post_list_size; i++) {
354 if (gd->flags & GD_FLG_POSTSTOP)
356 post_run_single(post_list + i,
364 for (i = 0; i < post_list_size; i++) {
365 if (strcmp(post_list[i].cmd, name) == 0)
369 if (i < post_list_size) {
371 return post_run_single(post_list + i,
380 static int post_info_single(struct post_test *test, int full)
382 if (test->flags & POST_MANUAL) {
385 " %s\n", test->cmd, test->name, test->desc);
387 printf(" %-15s - %s\n", test->cmd, test->name);
395 int post_info(char *name)
400 for (i = 0; i < post_list_size; i++)
401 post_info_single(post_list + i, 0);
405 for (i = 0; i < post_list_size; i++) {
406 if (strcmp(post_list[i].cmd, name) == 0)
410 if (i < post_list_size)
411 return post_info_single(post_list + i, 1);
417 int post_log(char *format, ...)
420 char printbuffer[CONFIG_SYS_PBSIZE];
422 va_start(args, format);
424 /* For this to work, printbuffer must be larger than
425 * anything we ever want to print.
427 vsprintf(printbuffer, format, args);
430 #ifdef CONFIG_LOGBUFFER
431 /* Send to the logbuffer */
432 logbuff_log(printbuffer);
434 /* Send to the stdout file */
441 #ifdef CONFIG_NEEDS_MANUAL_RELOC
442 void post_reloc(void)
447 * We have to relocate the test table manually
449 for (i = 0; i < post_list_size; i++) {
451 struct post_test *test = post_list + i;
454 addr = (ulong)(test->name) + gd->reloc_off;
455 test->name = (char *)addr;
459 addr = (ulong)(test->cmd) + gd->reloc_off;
460 test->cmd = (char *)addr;
464 addr = (ulong)(test->desc) + gd->reloc_off;
465 test->desc = (char *)addr;
469 addr = (ulong)(test->test) + gd->reloc_off;
470 test->test = (int (*)(int flags)) addr;
474 addr = (ulong)(test->init_f) + gd->reloc_off;
475 test->init_f = (int (*)(void)) addr;
479 addr = (ulong)(test->reloc) + gd->reloc_off;
480 test->reloc = (void (*)(void)) addr;
490 * Some tests (e.g. SYSMON) need the time when post_init_f started,
491 * but we cannot use get_timer() at this point.
493 * On PowerPC we implement it using the timebase register.
495 unsigned long post_time_ms(unsigned long base)
497 #if defined(CONFIG_PPC) || defined(CONFIG_ARM)
498 return (unsigned long)(get_ticks() / (get_tbclk() / CONFIG_SYS_HZ))
501 #warning "Not implemented yet"
502 return 0; /* Not implemented yet */