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 void post_bootmode_init (void)
41 DECLARE_GLOBAL_DATA_PTR;
42 int bootmode = post_bootmode_get (0);
45 bootmode = POST_POWERON;
46 } else if (bootmode == POST_POWERON) {
47 bootmode = POST_POWERNORMAL;
52 post_word_store (BOOTMODE_MAGIC | bootmode);
53 /* Reset activity record */
54 gd->post_log_word = 0;
57 int post_bootmode_get (unsigned int *last_test)
59 unsigned long word = post_word_load ();
62 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC) {
66 bootmode = word & 0xFF;
68 if (last_test && (bootmode & POST_POWERTEST)) {
69 *last_test = (word >> 8) & 0xFF;
75 void post_bootmode_clear (void)
80 /* POST tests run before relocation only mark status bits .... */
81 static void post_log_mark_start ( unsigned long testid )
83 DECLARE_GLOBAL_DATA_PTR;
84 gd->post_log_word |= (testid)<<16;
87 static void post_log_mark_succ ( unsigned long testid )
89 DECLARE_GLOBAL_DATA_PTR;
90 gd->post_log_word |= testid;
93 /* ... and the messages are output once we are relocated */
94 void post_output_backlog ( void )
96 DECLARE_GLOBAL_DATA_PTR;
99 for (j = 0; j < post_list_size; j++) {
100 if (gd->post_log_word & (post_list[j].testid<<16)) {
101 post_log ("POST %s ", post_list[j].cmd);
102 if (gd->post_log_word & post_list[j].testid)
103 post_log ("PASSED\n");
105 post_log ("FAILED\n");
110 static void post_bootmode_test_on (unsigned int last_test)
112 unsigned long word = post_word_load ();
114 word |= POST_POWERTEST;
116 word |= (last_test & 0xFF) << 8;
118 post_word_store (word);
121 static void post_bootmode_test_off (void)
123 unsigned long word = post_word_load ();
125 word &= ~POST_POWERTEST;
127 post_word_store (word);
130 static void post_get_flags (int *test_flags)
132 int flag[] = { POST_POWERON, POST_POWERNORMAL, POST_POWERFAIL };
133 char *var[] = { "post_poweron", "post_normal", "post_shutdown" };
134 int varnum = sizeof (var) / sizeof (var[0]);
135 char list[128]; /* long enough for POST list */
141 for (j = 0; j < post_list_size; j++) {
142 test_flags[j] = post_list[j].flags;
145 for (i = 0; i < varnum; i++) {
146 if (getenv_r (var[i], list, sizeof (list)) <= 0)
149 for (j = 0; j < post_list_size; j++) {
150 test_flags[j] &= ~flag[i];
156 while (*name && *name == ' ')
161 while (*s && *s != ' ')
168 for (j = 0; j < post_list_size; j++) {
169 if (strcmp (post_list[j].cmd, name) == 0) {
170 test_flags[j] |= flag[i];
175 if (j == post_list_size) {
176 printf ("No such test: %s\n", name);
184 static int post_run_single (struct post_test *test,
185 int test_flags, int flags, unsigned int i)
187 if ((flags & test_flags & POST_ALWAYS) &&
188 (flags & test_flags & POST_MEM)) {
191 if (!(flags & POST_REBOOT)) {
192 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
193 post_bootmode_test_on (i);
196 if (test_flags & POST_PREREL)
197 post_log_mark_start ( test->testid );
199 post_log ("POST %s ", test->cmd);
202 if (test_flags & POST_PREREL) {
203 if ((*test->test) (flags) == 0)
204 post_log_mark_succ ( test->testid );
206 if ((*test->test) (flags) != 0)
207 post_log ("FAILED\n");
209 post_log ("PASSED\n");
212 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
213 post_bootmode_test_off ();
222 int post_run (char *name, int flags)
225 int test_flags[POST_MAX_NUMBER];
227 post_get_flags (test_flags);
232 if (post_bootmode_get (&last) & POST_POWERTEST) {
233 if (last < post_list_size &&
234 (flags & test_flags[last] & POST_ALWAYS) &&
235 (flags & test_flags[last] & POST_MEM)) {
237 post_run_single (post_list + last,
239 flags | POST_REBOOT, last);
241 for (i = last + 1; i < post_list_size; i++) {
242 post_run_single (post_list + i,
248 for (i = 0; i < post_list_size; i++) {
249 post_run_single (post_list + i,
257 for (i = 0; i < post_list_size; i++) {
258 if (strcmp (post_list[i].cmd, name) == 0)
262 if (i < post_list_size) {
263 return post_run_single (post_list + i,
272 static int post_info_single (struct post_test *test, int full)
274 if (test->flags & POST_MANUAL) {
277 " %s\n", test->cmd, test->name, test->desc);
279 printf (" %-15s - %s\n", test->cmd, test->name);
287 int post_info (char *name)
292 for (i = 0; i < post_list_size; i++) {
293 post_info_single (post_list + i, 0);
298 for (i = 0; i < post_list_size; i++) {
299 if (strcmp (post_list[i].cmd, name) == 0)
303 if (i < post_list_size) {
304 return post_info_single (post_list + i, 1);
311 int post_log (char *format, ...)
315 char printbuffer[CFG_PBSIZE];
317 va_start (args, format);
319 /* For this to work, printbuffer must be larger than
320 * anything we ever want to print.
322 i = vsprintf (printbuffer, format, args);
325 #ifdef CONFIG_LOGBUFFER
326 /* Send to the logbuffer */
327 logbuff_log (printbuffer);
329 /* Send to the stdout file */
336 void post_reloc (void)
338 DECLARE_GLOBAL_DATA_PTR;
343 * We have to relocate the test table manually
345 for (i = 0; i < post_list_size; i++) {
347 struct post_test *test = post_list + i;
350 addr = (ulong) (test->name) + gd->reloc_off;
351 test->name = (char *) addr;
355 addr = (ulong) (test->cmd) + gd->reloc_off;
356 test->cmd = (char *) addr;
360 addr = (ulong) (test->desc) + gd->reloc_off;
361 test->desc = (char *) addr;
365 addr = (ulong) (test->test) + gd->reloc_off;
366 test->test = (int (*)(int flags)) addr;
371 #endif /* CONFIG_POST */