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_LOGBUFFER
33 DECLARE_GLOBAL_DATA_PTR;
35 #define POST_MAX_NUMBER 32
37 #define BOOTMODE_MAGIC 0xDEAD0000
44 for (i = 0; i < post_list_size; i++) {
45 struct post_test *test = post_list + i;
47 if (test->init_f && test->init_f()) {
52 gd->post_init_f_time = post_time_ms(0);
53 if (!gd->post_init_f_time) {
55 ("post/post.c: post_time_ms seems not to be implemented\n");
61 void post_bootmode_init(void)
63 int bootmode = post_bootmode_get(0);
66 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST)) {
67 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
68 } else if (bootmode == 0) {
69 newword = BOOTMODE_MAGIC | POST_POWERON;
70 } else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST) {
71 newword = BOOTMODE_MAGIC | POST_NORMAL;
74 newword = post_word_load() & ~POST_COLDBOOT;
78 /* We are booting after power-on */
79 newword |= POST_COLDBOOT;
82 post_word_store(newword);
84 /* Reset activity record */
85 gd->post_log_word = 0;
88 int post_bootmode_get(unsigned int *last_test)
90 unsigned long word = post_word_load();
93 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC) {
97 bootmode = word & 0x7F;
99 if (last_test && (bootmode & POST_POWERTEST)) {
100 *last_test = (word >> 8) & 0xFF;
106 /* POST tests run before relocation only mark status bits .... */
107 static void post_log_mark_start(unsigned long testid)
109 gd->post_log_word |= (testid) << 16;
112 static void post_log_mark_succ(unsigned long testid)
114 gd->post_log_word |= testid;
117 /* ... and the messages are output once we are relocated */
118 void post_output_backlog(void)
122 for (j = 0; j < post_list_size; j++) {
123 if (gd->post_log_word & (post_list[j].testid << 16)) {
124 post_log("POST %s ", post_list[j].cmd);
125 if (gd->post_log_word & post_list[j].testid)
126 post_log("PASSED\n");
128 post_log("FAILED\n");
129 show_boot_progress (-31);
135 static void post_bootmode_test_on(unsigned int last_test)
137 unsigned long word = post_word_load();
139 word |= POST_POWERTEST;
141 word |= (last_test & 0xFF) << 8;
143 post_word_store(word);
146 static void post_bootmode_test_off(void)
148 unsigned long word = post_word_load();
150 word &= ~POST_POWERTEST;
152 post_word_store(word);
155 static void post_get_flags(int *test_flags)
157 int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST };
158 char *var[] = { "post_poweron", "post_normal", "post_slowtest" };
159 int varnum = sizeof(var) / sizeof(var[0]);
160 char list[128]; /* long enough for POST list */
166 for (j = 0; j < post_list_size; j++) {
167 test_flags[j] = post_list[j].flags;
170 for (i = 0; i < varnum; i++) {
171 if (getenv_r(var[i], list, sizeof(list)) <= 0)
174 for (j = 0; j < post_list_size; j++) {
175 test_flags[j] &= ~flag[i];
181 while (*name && *name == ' ')
186 while (*s && *s != ' ')
193 for (j = 0; j < post_list_size; j++) {
194 if (strcmp(post_list[j].cmd, name) == 0) {
195 test_flags[j] |= flag[i];
200 if (j == post_list_size) {
201 printf("No such test: %s\n", name);
208 for (j = 0; j < post_list_size; j++) {
209 if (test_flags[j] & POST_POWERON) {
210 test_flags[j] |= POST_SLOWTEST;
215 static int post_run_single(struct post_test *test,
216 int test_flags, int flags, unsigned int i)
218 if ((flags & test_flags & POST_ALWAYS) &&
219 (flags & test_flags & POST_MEM)) {
222 if (!(flags & POST_REBOOT)) {
223 if ((test_flags & POST_REBOOT)
224 && !(flags & POST_MANUAL)) {
225 post_bootmode_test_on(i);
228 if (test_flags & POST_PREREL)
229 post_log_mark_start(test->testid);
231 post_log("POST %s ", test->cmd);
234 if (test_flags & POST_PREREL) {
235 if ((*test->test) (flags) == 0)
236 post_log_mark_succ(test->testid);
238 if ((*test->test) (flags) != 0) {
239 post_log("FAILED\n");
240 show_boot_progress (-32);
242 post_log("PASSED\n");
245 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
246 post_bootmode_test_off();
255 int post_run(char *name, int flags)
258 int test_flags[POST_MAX_NUMBER];
260 post_get_flags(test_flags);
265 if (post_bootmode_get(&last) & POST_POWERTEST) {
266 if (last < post_list_size &&
267 (flags & test_flags[last] & POST_ALWAYS) &&
268 (flags & test_flags[last] & POST_MEM)) {
270 post_run_single(post_list + last,
272 flags | POST_REBOOT, last);
274 for (i = last + 1; i < post_list_size; i++) {
275 post_run_single(post_list + i,
281 for (i = 0; i < post_list_size; i++) {
282 post_run_single(post_list + i,
283 test_flags[i], flags, i);
289 for (i = 0; i < post_list_size; i++) {
290 if (strcmp(post_list[i].cmd, name) == 0)
294 if (i < post_list_size) {
295 return post_run_single(post_list + i,
296 test_flags[i], flags, i);
303 static int post_info_single(struct post_test *test, int full)
305 if (test->flags & POST_MANUAL) {
308 " %s\n", test->cmd, test->name, test->desc);
310 printf(" %-15s - %s\n", test->cmd, test->name);
318 int post_info(char *name)
323 for (i = 0; i < post_list_size; i++) {
324 post_info_single(post_list + i, 0);
329 for (i = 0; i < post_list_size; i++) {
330 if (strcmp(post_list[i].cmd, name) == 0)
334 if (i < post_list_size) {
335 return post_info_single(post_list + i, 1);
342 int post_log(char *format, ...)
346 char printbuffer[CONFIG_SYS_PBSIZE];
348 va_start(args, format);
350 /* For this to work, printbuffer must be larger than
351 * anything we ever want to print.
353 i = vsprintf(printbuffer, format, args);
356 #ifdef CONFIG_LOGBUFFER
357 /* Send to the logbuffer */
358 logbuff_log(printbuffer);
360 /* Send to the stdout file */
367 void post_reloc(void)
372 * We have to relocate the test table manually
374 for (i = 0; i < post_list_size; i++) {
376 struct post_test *test = post_list + i;
379 addr = (ulong) (test->name) + gd->reloc_off;
380 test->name = (char *)addr;
384 addr = (ulong) (test->cmd) + gd->reloc_off;
385 test->cmd = (char *)addr;
389 addr = (ulong) (test->desc) + gd->reloc_off;
390 test->desc = (char *)addr;
394 addr = (ulong) (test->test) + gd->reloc_off;
395 test->test = (int (*)(int flags))addr;
399 addr = (ulong) (test->init_f) + gd->reloc_off;
400 test->init_f = (int (*)(void))addr;
404 addr = (ulong) (test->reloc) + gd->reloc_off;
405 test->reloc = (void (*)(void))addr;
413 * Some tests (e.g. SYSMON) need the time when post_init_f started,
414 * but we cannot use get_timer() at this point.
416 * On PowerPC we implement it using the timebase register.
418 unsigned long post_time_ms(unsigned long base)
420 return (unsigned long)get_ticks() / (get_tbclk() / CONFIG_SYS_HZ) - base;