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,
29 #ifdef CONFIG_LOGBUFFER
35 DECLARE_GLOBAL_DATA_PTR;
37 #define POST_MAX_NUMBER 32
39 #define BOOTMODE_MAGIC 0xDEAD0000
41 int post_init_f (void)
46 for (i = 0; i < post_list_size; i++) {
47 struct post_test *test = post_list + i;
49 if (test->init_f && test->init_f()) {
54 gd->post_init_f_time = post_time_ms(0);
55 if (!gd->post_init_f_time)
57 printf("post/post.c: post_time_ms seems not to be implemented\n");
63 void post_bootmode_init (void)
65 int bootmode = post_bootmode_get (0);
68 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST)) {
69 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
70 } else if (bootmode == 0) {
71 newword = BOOTMODE_MAGIC | POST_POWERON;
72 } else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST) {
73 newword = BOOTMODE_MAGIC | POST_NORMAL;
76 newword = post_word_load () & ~POST_COLDBOOT;
81 /* We are booting after power-on */
82 newword |= POST_COLDBOOT;
85 post_word_store (newword);
87 /* Reset activity record */
88 gd->post_log_word = 0;
91 int post_bootmode_get (unsigned int *last_test)
93 unsigned long word = post_word_load ();
96 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC) {
100 bootmode = word & 0x7F;
102 if (last_test && (bootmode & POST_POWERTEST)) {
103 *last_test = (word >> 8) & 0xFF;
109 /* POST tests run before relocation only mark status bits .... */
110 static void post_log_mark_start ( unsigned long testid )
112 gd->post_log_word |= (testid)<<16;
115 static void post_log_mark_succ ( unsigned long testid )
117 gd->post_log_word |= testid;
120 /* ... and the messages are output once we are relocated */
121 void post_output_backlog ( void )
125 for (j = 0; j < post_list_size; j++) {
126 if (gd->post_log_word & (post_list[j].testid<<16)) {
127 post_log ("POST %s ", post_list[j].cmd);
128 if (gd->post_log_word & post_list[j].testid)
129 post_log ("PASSED\n");
131 post_log ("FAILED\n");
132 #ifdef CONFIG_SHOW_BOOT_PROGRESS
133 show_boot_progress(-31);
140 static void post_bootmode_test_on (unsigned int last_test)
142 unsigned long word = post_word_load ();
144 word |= POST_POWERTEST;
146 word |= (last_test & 0xFF) << 8;
148 post_word_store (word);
151 static void post_bootmode_test_off (void)
153 unsigned long word = post_word_load ();
155 word &= ~POST_POWERTEST;
157 post_word_store (word);
160 static void post_get_flags (int *test_flags)
162 int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST };
163 char *var[] = { "post_poweron", "post_normal", "post_slowtest" };
164 int varnum = sizeof (var) / sizeof (var[0]);
165 char list[128]; /* long enough for POST list */
171 for (j = 0; j < post_list_size; j++) {
172 test_flags[j] = post_list[j].flags;
175 for (i = 0; i < varnum; i++) {
176 if (getenv_r (var[i], list, sizeof (list)) <= 0)
179 for (j = 0; j < post_list_size; j++) {
180 test_flags[j] &= ~flag[i];
186 while (*name && *name == ' ')
191 while (*s && *s != ' ')
198 for (j = 0; j < post_list_size; j++) {
199 if (strcmp (post_list[j].cmd, name) == 0) {
200 test_flags[j] |= flag[i];
205 if (j == post_list_size) {
206 printf ("No such test: %s\n", name);
213 for (j = 0; j < post_list_size; j++) {
214 if (test_flags[j] & POST_POWERON) {
215 test_flags[j] |= POST_SLOWTEST;
220 static int post_run_single (struct post_test *test,
221 int test_flags, int flags, unsigned int i)
223 if ((flags & test_flags & POST_ALWAYS) &&
224 (flags & test_flags & POST_MEM)) {
227 if (!(flags & POST_REBOOT)) {
228 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
229 post_bootmode_test_on (i);
232 if (test_flags & POST_PREREL)
233 post_log_mark_start ( test->testid );
235 post_log ("POST %s ", test->cmd);
238 if (test_flags & POST_PREREL) {
239 if ((*test->test) (flags) == 0)
240 post_log_mark_succ ( test->testid );
242 if ((*test->test) (flags) != 0) {
243 post_log ("FAILED\n");
244 #ifdef CONFIG_SHOW_BOOT_PROGRESS
245 show_boot_progress(-32);
249 post_log ("PASSED\n");
252 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
253 post_bootmode_test_off ();
262 int post_run (char *name, int flags)
265 int test_flags[POST_MAX_NUMBER];
267 post_get_flags (test_flags);
272 if (post_bootmode_get (&last) & POST_POWERTEST) {
273 if (last < post_list_size &&
274 (flags & test_flags[last] & POST_ALWAYS) &&
275 (flags & test_flags[last] & POST_MEM)) {
277 post_run_single (post_list + last,
279 flags | POST_REBOOT, last);
281 for (i = last + 1; i < post_list_size; i++) {
282 post_run_single (post_list + i,
288 for (i = 0; i < post_list_size; i++) {
289 post_run_single (post_list + i,
297 for (i = 0; i < post_list_size; i++) {
298 if (strcmp (post_list[i].cmd, name) == 0)
302 if (i < post_list_size) {
303 return post_run_single (post_list + i,
312 static int post_info_single (struct post_test *test, int full)
314 if (test->flags & POST_MANUAL) {
317 " %s\n", test->cmd, test->name, test->desc);
319 printf (" %-15s - %s\n", test->cmd, test->name);
327 int post_info (char *name)
332 for (i = 0; i < post_list_size; i++) {
333 post_info_single (post_list + i, 0);
338 for (i = 0; i < post_list_size; i++) {
339 if (strcmp (post_list[i].cmd, name) == 0)
343 if (i < post_list_size) {
344 return post_info_single (post_list + i, 1);
351 int post_log (char *format, ...)
355 char printbuffer[CFG_PBSIZE];
357 va_start (args, format);
359 /* For this to work, printbuffer must be larger than
360 * anything we ever want to print.
362 i = vsprintf (printbuffer, format, args);
365 #ifdef CONFIG_LOGBUFFER
366 /* Send to the logbuffer */
367 logbuff_log (printbuffer);
369 /* Send to the stdout file */
376 void post_reloc (void)
381 * We have to relocate the test table manually
383 for (i = 0; i < post_list_size; i++) {
385 struct post_test *test = post_list + i;
388 addr = (ulong) (test->name) + gd->reloc_off;
389 test->name = (char *) addr;
393 addr = (ulong) (test->cmd) + gd->reloc_off;
394 test->cmd = (char *) addr;
398 addr = (ulong) (test->desc) + gd->reloc_off;
399 test->desc = (char *) addr;
403 addr = (ulong) (test->test) + gd->reloc_off;
404 test->test = (int (*)(int flags)) addr;
408 addr = (ulong) (test->init_f) + gd->reloc_off;
409 test->init_f = (int (*)(void)) addr;
413 addr = (ulong) (test->reloc) + gd->reloc_off;
414 test->reloc = (void (*)(void)) addr;
423 * Some tests (e.g. SYSMON) need the time when post_init_f started,
424 * but we cannot use get_timer() at this point.
426 * On PowerPC we implement it using the timebase register.
428 unsigned long post_time_ms (unsigned long base)
431 return (unsigned long)get_ticks () / (get_tbclk () / CFG_HZ) - base;
433 #warning "Not implemented yet"
434 return 0; /* Not implemented yet */
438 #endif /* CONFIG_POST */