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
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 ("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 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST)) {
70 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
71 } else if (bootmode == 0) {
72 newword = BOOTMODE_MAGIC | POST_POWERON;
73 } else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST) {
74 newword = BOOTMODE_MAGIC | POST_NORMAL;
77 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 DECLARE_GLOBAL_DATA_PTR;
113 gd->post_log_word |= (testid) << 16;
116 static void post_log_mark_succ(unsigned long testid)
118 DECLARE_GLOBAL_DATA_PTR;
119 gd->post_log_word |= testid;
122 /* ... and the messages are output once we are relocated */
123 void post_output_backlog(void)
125 DECLARE_GLOBAL_DATA_PTR;
128 for (j = 0; j < post_list_size; j++) {
129 if (gd->post_log_word & (post_list[j].testid << 16)) {
130 post_log("POST %s ", post_list[j].cmd);
131 if (gd->post_log_word & post_list[j].testid)
132 post_log("PASSED\n");
134 post_log("FAILED\n");
135 show_boot_progress (-31);
141 static void post_bootmode_test_on(unsigned int last_test)
143 unsigned long word = post_word_load();
145 word |= POST_POWERTEST;
147 word |= (last_test & 0xFF) << 8;
149 post_word_store(word);
152 static void post_bootmode_test_off(void)
154 unsigned long word = post_word_load();
156 word &= ~POST_POWERTEST;
158 post_word_store(word);
161 static void post_get_flags(int *test_flags)
163 int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST };
164 char *var[] = { "post_poweron", "post_normal", "post_slowtest" };
165 int varnum = sizeof(var) / sizeof(var[0]);
166 char list[128]; /* long enough for POST list */
172 for (j = 0; j < post_list_size; j++) {
173 test_flags[j] = post_list[j].flags;
176 for (i = 0; i < varnum; i++) {
177 if (getenv_r(var[i], list, sizeof(list)) <= 0)
180 for (j = 0; j < post_list_size; j++) {
181 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);
214 for (j = 0; j < post_list_size; j++) {
215 if (test_flags[j] & POST_POWERON) {
216 test_flags[j] |= POST_SLOWTEST;
221 static int post_run_single(struct post_test *test,
222 int test_flags, int flags, unsigned int i)
224 if ((flags & test_flags & POST_ALWAYS) &&
225 (flags & test_flags & POST_MEM)) {
228 if (!(flags & POST_REBOOT)) {
229 if ((test_flags & POST_REBOOT)
230 && !(flags & POST_MANUAL)) {
231 post_bootmode_test_on(i);
234 if (test_flags & POST_PREREL)
235 post_log_mark_start(test->testid);
237 post_log("POST %s ", test->cmd);
240 if (test_flags & POST_PREREL) {
241 if ((*test->test) (flags) == 0)
242 post_log_mark_succ(test->testid);
244 if ((*test->test) (flags) != 0) {
245 post_log("FAILED\n");
246 show_boot_progress (-32);
248 post_log("PASSED\n");
251 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
252 post_bootmode_test_off();
261 int post_run(char *name, int flags)
264 int test_flags[POST_MAX_NUMBER];
266 post_get_flags(test_flags);
271 if (post_bootmode_get(&last) & POST_POWERTEST) {
272 if (last < post_list_size &&
273 (flags & test_flags[last] & POST_ALWAYS) &&
274 (flags & test_flags[last] & POST_MEM)) {
276 post_run_single(post_list + last,
278 flags | POST_REBOOT, last);
280 for (i = last + 1; i < post_list_size; i++) {
281 post_run_single(post_list + i,
287 for (i = 0; i < post_list_size; i++) {
288 post_run_single(post_list + i,
289 test_flags[i], flags, i);
295 for (i = 0; i < post_list_size; i++) {
296 if (strcmp(post_list[i].cmd, name) == 0)
300 if (i < post_list_size) {
301 return post_run_single(post_list + i,
302 test_flags[i], flags, i);
309 static int post_info_single(struct post_test *test, int full)
311 if (test->flags & POST_MANUAL) {
314 " %s\n", test->cmd, test->name, test->desc);
316 printf(" %-15s - %s\n", test->cmd, test->name);
324 int post_info(char *name)
329 for (i = 0; i < post_list_size; i++) {
330 post_info_single(post_list + i, 0);
335 for (i = 0; i < post_list_size; i++) {
336 if (strcmp(post_list[i].cmd, name) == 0)
340 if (i < post_list_size) {
341 return post_info_single(post_list + i, 1);
348 int post_log(char *format, ...)
352 char printbuffer[CFG_PBSIZE];
354 va_start(args, format);
356 /* For this to work, printbuffer must be larger than
357 * anything we ever want to print.
359 i = vsprintf(printbuffer, format, args);
362 #ifdef CONFIG_LOGBUFFER
363 /* Send to the logbuffer */
364 logbuff_log(printbuffer);
366 /* Send to the stdout file */
373 void post_reloc(void)
375 DECLARE_GLOBAL_DATA_PTR;
380 * We have to relocate the test table manually
382 for (i = 0; i < post_list_size; i++) {
384 struct post_test *test = post_list + i;
387 addr = (ulong) (test->name) + gd->reloc_off;
388 test->name = (char *)addr;
392 addr = (ulong) (test->cmd) + gd->reloc_off;
393 test->cmd = (char *)addr;
397 addr = (ulong) (test->desc) + gd->reloc_off;
398 test->desc = (char *)addr;
402 addr = (ulong) (test->test) + gd->reloc_off;
403 test->test = (int (*)(int flags))addr;
407 addr = (ulong) (test->init_f) + gd->reloc_off;
408 test->init_f = (int (*)(void))addr;
412 addr = (ulong) (test->reloc) + gd->reloc_off;
413 test->reloc = (void (*)(void))addr;
421 * Some tests (e.g. SYSMON) need the time when post_init_f started,
422 * but we cannot use get_timer() at this point.
424 * On PowerPC we implement it using the timebase register.
426 unsigned long post_time_ms(unsigned long base)
428 return (unsigned long)get_ticks() / (get_tbclk() / CFG_HZ) - base;
431 #endif /* CONFIG_POST */