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 #define POST_MAX_NUMBER 32
37 #define BOOTMODE_MAGIC 0xDEAD0000
39 int post_init_f (void)
41 DECLARE_GLOBAL_DATA_PTR;
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 DECLARE_GLOBAL_DATA_PTR;
66 int bootmode = post_bootmode_get (0);
69 bootmode = POST_POWERON;
70 } else if (bootmode == POST_POWERON) {
71 bootmode = POST_POWERNORMAL;
76 post_word_store (BOOTMODE_MAGIC | bootmode);
77 /* Reset activity record */
78 gd->post_log_word = 0;
81 int post_bootmode_get (unsigned int *last_test)
83 unsigned long word = post_word_load ();
86 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC) {
90 bootmode = word & 0xFF;
92 if (last_test && (bootmode & POST_POWERTEST)) {
93 *last_test = (word >> 8) & 0xFF;
99 void post_bootmode_clear (void)
104 /* POST tests run before relocation only mark status bits .... */
105 static void post_log_mark_start ( unsigned long testid )
107 DECLARE_GLOBAL_DATA_PTR;
108 gd->post_log_word |= (testid)<<16;
111 static void post_log_mark_succ ( unsigned long testid )
113 DECLARE_GLOBAL_DATA_PTR;
114 gd->post_log_word |= testid;
117 /* ... and the messages are output once we are relocated */
118 void post_output_backlog ( void )
120 DECLARE_GLOBAL_DATA_PTR;
123 for (j = 0; j < post_list_size; j++) {
124 if (gd->post_log_word & (post_list[j].testid<<16)) {
125 post_log ("POST %s ", post_list[j].cmd);
126 if (gd->post_log_word & post_list[j].testid)
127 post_log ("PASSED\n");
129 post_log ("FAILED\n");
134 static void post_bootmode_test_on (unsigned int last_test)
136 unsigned long word = post_word_load ();
138 word |= POST_POWERTEST;
140 word |= (last_test & 0xFF) << 8;
142 post_word_store (word);
145 static void post_bootmode_test_off (void)
147 unsigned long word = post_word_load ();
149 word &= ~POST_POWERTEST;
151 post_word_store (word);
154 static void post_get_flags (int *test_flags)
156 int flag[] = { POST_POWERON, POST_POWERNORMAL, POST_POWERFAIL };
157 char *var[] = { "post_poweron", "post_normal", "post_shutdown" };
158 int varnum = sizeof (var) / sizeof (var[0]);
159 char list[128]; /* long enough for POST list */
165 for (j = 0; j < post_list_size; j++) {
166 test_flags[j] = post_list[j].flags;
169 for (i = 0; i < varnum; i++) {
170 if (getenv_r (var[i], list, sizeof (list)) <= 0)
173 for (j = 0; j < post_list_size; j++) {
174 test_flags[j] &= ~flag[i];
180 while (*name && *name == ' ')
185 while (*s && *s != ' ')
192 for (j = 0; j < post_list_size; j++) {
193 if (strcmp (post_list[j].cmd, name) == 0) {
194 test_flags[j] |= flag[i];
199 if (j == post_list_size) {
200 printf ("No such test: %s\n", name);
208 static int post_run_single (struct post_test *test,
209 int test_flags, int flags, unsigned int i)
211 if ((flags & test_flags & POST_ALWAYS) &&
212 (flags & test_flags & POST_MEM)) {
215 if (!(flags & POST_REBOOT)) {
216 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
217 post_bootmode_test_on (i);
220 if (test_flags & POST_PREREL)
221 post_log_mark_start ( test->testid );
223 post_log ("POST %s ", test->cmd);
226 if (test_flags & POST_PREREL) {
227 if ((*test->test) (flags) == 0)
228 post_log_mark_succ ( test->testid );
230 if ((*test->test) (flags) != 0)
231 post_log ("FAILED\n");
233 post_log ("PASSED\n");
236 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
237 post_bootmode_test_off ();
246 int post_run (char *name, int flags)
249 int test_flags[POST_MAX_NUMBER];
251 post_get_flags (test_flags);
256 if (post_bootmode_get (&last) & POST_POWERTEST) {
257 if (last < post_list_size &&
258 (flags & test_flags[last] & POST_ALWAYS) &&
259 (flags & test_flags[last] & POST_MEM)) {
261 post_run_single (post_list + last,
263 flags | POST_REBOOT, last);
265 for (i = last + 1; i < post_list_size; i++) {
266 post_run_single (post_list + i,
272 for (i = 0; i < post_list_size; i++) {
273 post_run_single (post_list + i,
281 for (i = 0; i < post_list_size; i++) {
282 if (strcmp (post_list[i].cmd, name) == 0)
286 if (i < post_list_size) {
287 return post_run_single (post_list + i,
296 static int post_info_single (struct post_test *test, int full)
298 if (test->flags & POST_MANUAL) {
301 " %s\n", test->cmd, test->name, test->desc);
303 printf (" %-15s - %s\n", test->cmd, test->name);
311 int post_info (char *name)
316 for (i = 0; i < post_list_size; i++) {
317 post_info_single (post_list + i, 0);
322 for (i = 0; i < post_list_size; i++) {
323 if (strcmp (post_list[i].cmd, name) == 0)
327 if (i < post_list_size) {
328 return post_info_single (post_list + i, 1);
335 int post_log (char *format, ...)
339 char printbuffer[CFG_PBSIZE];
341 va_start (args, format);
343 /* For this to work, printbuffer must be larger than
344 * anything we ever want to print.
346 i = vsprintf (printbuffer, format, args);
349 #ifdef CONFIG_LOGBUFFER
350 /* Send to the logbuffer */
351 logbuff_log (printbuffer);
353 /* Send to the stdout file */
360 void post_reloc (void)
362 DECLARE_GLOBAL_DATA_PTR;
367 * We have to relocate the test table manually
369 for (i = 0; i < post_list_size; i++) {
371 struct post_test *test = post_list + i;
374 addr = (ulong) (test->name) + gd->reloc_off;
375 test->name = (char *) addr;
379 addr = (ulong) (test->cmd) + gd->reloc_off;
380 test->cmd = (char *) addr;
384 addr = (ulong) (test->desc) + gd->reloc_off;
385 test->desc = (char *) addr;
389 addr = (ulong) (test->test) + gd->reloc_off;
390 test->test = (int (*)(int flags)) addr;
394 addr = (ulong) (test->init_f) + gd->reloc_off;
395 test->init_f = (int (*)(void)) addr;
399 addr = (ulong) (test->reloc) + gd->reloc_off;
400 test->reloc = (void (*)(void)) addr;
409 * Some tests (e.g. SYSMON) need the time when post_init_f started,
410 * but we cannot use get_timer() at this point.
412 * On PowerPC we implement it using the timebase register.
414 unsigned long post_time_ms (unsigned long base)
417 return (unsigned long)get_ticks () / (get_tbclk () / CFG_HZ) - base;
419 return 0; /* Not implemented yet */
423 #endif /* CONFIG_POST */