blob: b3ed2e1b49819fb488587136c1dab9a79cf2bce1 [file] [log] [blame]
wdenka042ac82002-09-12 22:36:57 +00001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
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.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24#include <common.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020025#include <stdio_dev.h>
wdenka042ac82002-09-12 22:36:57 +000026#include <watchdog.h>
Christian Rieschc90a4dd2011-12-09 16:54:02 +010027#include <div64.h>
wdenka042ac82002-09-12 22:36:57 +000028#include <post.h>
29
Mike Frysinger9146d132011-05-10 07:01:21 +000030#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
31#include <asm/gpio.h>
32#endif
33
wdenk56f94be2002-11-05 16:35:14 +000034#ifdef CONFIG_LOGBUFFER
35#include <logbuff.h>
36#endif
37
Wolfgang Denkd87080b2006-03-31 18:32:53 +020038DECLARE_GLOBAL_DATA_PTR;
39
wdenka042ac82002-09-12 22:36:57 +000040#define POST_MAX_NUMBER 32
41
42#define BOOTMODE_MAGIC 0xDEAD0000
43
Heiko Schochere92372c2011-10-12 01:18:05 +000044int post_init_f(void)
wdenk4532cb62003-04-27 22:52:51 +000045{
wdenk4532cb62003-04-27 22:52:51 +000046 int res = 0;
47 unsigned int i;
48
49 for (i = 0; i < post_list_size; i++) {
50 struct post_test *test = post_list + i;
51
Wolfgang Denk50da8372011-10-29 09:42:22 +000052 if (test->init_f && test->init_f())
wdenk4532cb62003-04-27 22:52:51 +000053 res = -1;
wdenk4532cb62003-04-27 22:52:51 +000054 }
wdenk8bde7f72003-06-27 21:31:46 +000055
wdenk4532cb62003-04-27 22:52:51 +000056 gd->post_init_f_time = post_time_ms(0);
57 if (!gd->post_init_f_time)
Heiko Schochere92372c2011-10-12 01:18:05 +000058 printf("%s: post_time_ms not implemented\n", __FILE__);
wdenk4532cb62003-04-27 22:52:51 +000059
60 return res;
61}
62
Stefan Roese39ff7d52009-12-03 06:24:30 +010063/*
64 * Supply a default implementation for post_hotkeys_pressed() for boards
65 * without hotkey support. We always return 0 here, so that the
66 * long-running tests won't be started.
67 *
68 * Boards with hotkey support can override this weak default function
69 * by defining one in their board specific code.
70 */
71int __post_hotkeys_pressed(void)
72{
Mike Frysinger9146d132011-05-10 07:01:21 +000073#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
74 int ret;
75 unsigned gpio = CONFIG_SYS_POST_HOTKEYS_GPIO;
76
77 ret = gpio_request(gpio, "hotkeys");
78 if (ret) {
79 printf("POST: gpio hotkey request failed\n");
80 return 0;
81 }
82
83 gpio_direction_input(gpio);
84 ret = gpio_get_value(gpio);
85 gpio_free(gpio);
86
87 return ret;
88#endif
89
Stefan Roese39ff7d52009-12-03 06:24:30 +010090 return 0; /* No hotkeys supported */
91}
92int post_hotkeys_pressed(void)
93 __attribute__((weak, alias("__post_hotkeys_pressed")));
94
95
Heiko Schochere92372c2011-10-12 01:18:05 +000096void post_bootmode_init(void)
wdenka042ac82002-09-12 22:36:57 +000097{
Heiko Schochere92372c2011-10-12 01:18:05 +000098 int bootmode = post_bootmode_get(0);
wdenk27b207f2003-07-24 23:38:38 +000099 int newword;
wdenk42d1f032003-10-15 23:53:47 +0000100
Heiko Schochere92372c2011-10-12 01:18:05 +0000101 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST))
wdenk27b207f2003-07-24 23:38:38 +0000102 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
Heiko Schochere92372c2011-10-12 01:18:05 +0000103 else if (bootmode == 0)
wdenk27b207f2003-07-24 23:38:38 +0000104 newword = BOOTMODE_MAGIC | POST_POWERON;
Heiko Schochere92372c2011-10-12 01:18:05 +0000105 else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST)
wdenk27b207f2003-07-24 23:38:38 +0000106 newword = BOOTMODE_MAGIC | POST_NORMAL;
Heiko Schochere92372c2011-10-12 01:18:05 +0000107 else
wdenk27b207f2003-07-24 23:38:38 +0000108 /* Use old value */
Wolfgang Denk50da8372011-10-29 09:42:22 +0000109 newword = post_word_load() & ~POST_COLDBOOT;
wdenka042ac82002-09-12 22:36:57 +0000110
wdenk27b207f2003-07-24 23:38:38 +0000111 if (bootmode == 0)
wdenk27b207f2003-07-24 23:38:38 +0000112 /* We are booting after power-on */
113 newword |= POST_COLDBOOT;
wdenk27b207f2003-07-24 23:38:38 +0000114
Heiko Schochere92372c2011-10-12 01:18:05 +0000115 post_word_store(newword);
wdenk27b207f2003-07-24 23:38:38 +0000116
wdenk228f29a2002-12-08 09:53:23 +0000117 /* Reset activity record */
118 gd->post_log_word = 0;
Valentin Longchamp79843952011-08-03 02:37:01 +0000119 gd->post_log_res = 0;
wdenka042ac82002-09-12 22:36:57 +0000120}
121
Heiko Schochere92372c2011-10-12 01:18:05 +0000122int post_bootmode_get(unsigned int *last_test)
wdenka042ac82002-09-12 22:36:57 +0000123{
Heiko Schochere92372c2011-10-12 01:18:05 +0000124 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000125 int bootmode;
126
Heiko Schochere92372c2011-10-12 01:18:05 +0000127 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC)
wdenka042ac82002-09-12 22:36:57 +0000128 return 0;
wdenka042ac82002-09-12 22:36:57 +0000129
wdenk27b207f2003-07-24 23:38:38 +0000130 bootmode = word & 0x7F;
wdenka042ac82002-09-12 22:36:57 +0000131
Heiko Schochere92372c2011-10-12 01:18:05 +0000132 if (last_test && (bootmode & POST_POWERTEST))
wdenka042ac82002-09-12 22:36:57 +0000133 *last_test = (word >> 8) & 0xFF;
wdenka042ac82002-09-12 22:36:57 +0000134
135 return bootmode;
136}
137
wdenk228f29a2002-12-08 09:53:23 +0000138/* POST tests run before relocation only mark status bits .... */
Heiko Schochere92372c2011-10-12 01:18:05 +0000139static void post_log_mark_start(unsigned long testid)
wdenk228f29a2002-12-08 09:53:23 +0000140{
Valentin Longchamp79843952011-08-03 02:37:01 +0000141 gd->post_log_word |= testid;
wdenk228f29a2002-12-08 09:53:23 +0000142}
143
Heiko Schochere92372c2011-10-12 01:18:05 +0000144static void post_log_mark_succ(unsigned long testid)
wdenk228f29a2002-12-08 09:53:23 +0000145{
Valentin Longchamp79843952011-08-03 02:37:01 +0000146 gd->post_log_res |= testid;
wdenk228f29a2002-12-08 09:53:23 +0000147}
148
149/* ... and the messages are output once we are relocated */
Heiko Schochere92372c2011-10-12 01:18:05 +0000150void post_output_backlog(void)
wdenk228f29a2002-12-08 09:53:23 +0000151{
wdenk228f29a2002-12-08 09:53:23 +0000152 int j;
153
154 for (j = 0; j < post_list_size; j++) {
Valentin Longchamp79843952011-08-03 02:37:01 +0000155 if (gd->post_log_word & (post_list[j].testid)) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000156 post_log("POST %s ", post_list[j].cmd);
Valentin Longchamp79843952011-08-03 02:37:01 +0000157 if (gd->post_log_res & post_list[j].testid)
Wolfgang Denk50da8372011-10-29 09:42:22 +0000158 post_log("PASSED\n");
wdenk63e73c92004-02-23 22:22:28 +0000159 else {
Heiko Schochere92372c2011-10-12 01:18:05 +0000160 post_log("FAILED\n");
Simon Glass770605e2012-02-13 13:51:18 +0000161 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
wdenk63e73c92004-02-23 22:22:28 +0000162 }
wdenk228f29a2002-12-08 09:53:23 +0000163 }
164 }
165}
166
Heiko Schochere92372c2011-10-12 01:18:05 +0000167static void post_bootmode_test_on(unsigned int last_test)
wdenka042ac82002-09-12 22:36:57 +0000168{
Heiko Schochere92372c2011-10-12 01:18:05 +0000169 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000170
171 word |= POST_POWERTEST;
172
173 word |= (last_test & 0xFF) << 8;
174
Heiko Schochere92372c2011-10-12 01:18:05 +0000175 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000176}
177
Heiko Schochere92372c2011-10-12 01:18:05 +0000178static void post_bootmode_test_off(void)
wdenka042ac82002-09-12 22:36:57 +0000179{
Heiko Schochere92372c2011-10-12 01:18:05 +0000180 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000181
182 word &= ~POST_POWERTEST;
183
Heiko Schochere92372c2011-10-12 01:18:05 +0000184 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000185}
186
Valentin Longchamp212a0ca2011-08-03 02:37:02 +0000187#ifndef CONFIG_POST_SKIP_ENV_FLAGS
188static void post_get_env_flags(int *test_flags)
wdenka042ac82002-09-12 22:36:57 +0000189{
Yuri Tikhonove262efe2008-02-04 14:11:03 +0100190 int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST,
191 POST_CRITICAL };
192 char *var[] = { "post_poweron", "post_normal", "post_slowtest",
193 "post_critical" };
Mike Frysingerd2397812011-05-10 07:28:35 +0000194 int varnum = ARRAY_SIZE(var);
wdenka042ac82002-09-12 22:36:57 +0000195 char list[128]; /* long enough for POST list */
196 char *name;
197 char *s;
198 int last;
199 int i, j;
200
wdenka042ac82002-09-12 22:36:57 +0000201 for (i = 0; i < varnum; i++) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000202 if (getenv_f(var[i], list, sizeof(list)) <= 0)
wdenka042ac82002-09-12 22:36:57 +0000203 continue;
204
Wolfgang Denk50da8372011-10-29 09:42:22 +0000205 for (j = 0; j < post_list_size; j++)
wdenka042ac82002-09-12 22:36:57 +0000206 test_flags[j] &= ~flag[i];
wdenka042ac82002-09-12 22:36:57 +0000207
208 last = 0;
209 name = list;
210 while (!last) {
211 while (*name && *name == ' ')
212 name++;
213 if (*name == 0)
214 break;
215 s = name + 1;
216 while (*s && *s != ' ')
217 s++;
218 if (*s == 0)
219 last = 1;
220 else
221 *s = 0;
222
223 for (j = 0; j < post_list_size; j++) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000224 if (strcmp(post_list[j].cmd, name) == 0) {
wdenka042ac82002-09-12 22:36:57 +0000225 test_flags[j] |= flag[i];
226 break;
227 }
228 }
229
Heiko Schochere92372c2011-10-12 01:18:05 +0000230 if (j == post_list_size)
Wolfgang Denk50da8372011-10-29 09:42:22 +0000231 printf("No such test: %s\n", name);
wdenka042ac82002-09-12 22:36:57 +0000232
233 name = s + 1;
234 }
235 }
Valentin Longchamp212a0ca2011-08-03 02:37:02 +0000236}
237#endif
238
239static void post_get_flags(int *test_flags)
240{
241 int j;
242
243 for (j = 0; j < post_list_size; j++)
244 test_flags[j] = post_list[j].flags;
245
246#ifndef CONFIG_POST_SKIP_ENV_FLAGS
247 post_get_env_flags(test_flags);
248#endif
wdenk6dff5522003-07-15 07:45:49 +0000249
Heiko Schochere92372c2011-10-12 01:18:05 +0000250 for (j = 0; j < post_list_size; j++)
251 if (test_flags[j] & POST_POWERON)
wdenk6dff5522003-07-15 07:45:49 +0000252 test_flags[j] |= POST_SLOWTEST;
wdenka042ac82002-09-12 22:36:57 +0000253}
254
Heiko Schochere92372c2011-10-12 01:18:05 +0000255void __show_post_progress(unsigned int test_num, int before, int result)
Michael Zaidmane070a562010-03-01 11:47:36 +0200256{
257}
Heiko Schochere92372c2011-10-12 01:18:05 +0000258void show_post_progress(unsigned int, int, int)
Michael Zaidmane070a562010-03-01 11:47:36 +0200259 __attribute__((weak, alias("__show_post_progress")));
260
Heiko Schochere92372c2011-10-12 01:18:05 +0000261static int post_run_single(struct post_test *test,
wdenka042ac82002-09-12 22:36:57 +0000262 int test_flags, int flags, unsigned int i)
263{
264 if ((flags & test_flags & POST_ALWAYS) &&
265 (flags & test_flags & POST_MEM)) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000266 WATCHDOG_RESET();
wdenka042ac82002-09-12 22:36:57 +0000267
268 if (!(flags & POST_REBOOT)) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000269 if ((test_flags & POST_REBOOT) &&
270 !(flags & POST_MANUAL)) {
271 post_bootmode_test_on(
Yuri Tikhonove262efe2008-02-04 14:11:03 +0100272 (gd->flags & GD_FLG_POSTFAIL) ?
273 POST_FAIL_SAVE | i : i);
wdenka042ac82002-09-12 22:36:57 +0000274 }
275
wdenk228f29a2002-12-08 09:53:23 +0000276 if (test_flags & POST_PREREL)
Heiko Schochere92372c2011-10-12 01:18:05 +0000277 post_log_mark_start(test->testid);
wdenk228f29a2002-12-08 09:53:23 +0000278 else
Heiko Schochere92372c2011-10-12 01:18:05 +0000279 post_log("POST %s ", test->cmd);
wdenka042ac82002-09-12 22:36:57 +0000280 }
281
Michael Zaidmane070a562010-03-01 11:47:36 +0200282 show_post_progress(i, POST_BEFORE, POST_FAILED);
283
wdenk228f29a2002-12-08 09:53:23 +0000284 if (test_flags & POST_PREREL) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000285 if ((*test->test)(flags) == 0) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000286 post_log_mark_succ(test->testid);
Michael Zaidmane070a562010-03-01 11:47:36 +0200287 show_post_progress(i, POST_AFTER, POST_PASSED);
Wolfgang Denk50da8372011-10-29 09:42:22 +0000288 } else {
Michael Zaidmane070a562010-03-01 11:47:36 +0200289 show_post_progress(i, POST_AFTER, POST_FAILED);
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200290 if (test_flags & POST_CRITICAL)
291 gd->flags |= GD_FLG_POSTFAIL;
292 if (test_flags & POST_STOP)
293 gd->flags |= GD_FLG_POSTSTOP;
294 }
wdenk228f29a2002-12-08 09:53:23 +0000295 } else {
James Kosin975afc32011-07-14 08:15:06 +0000296 if ((*test->test)(flags) != 0) {
297 post_log("FAILED\n");
Simon Glass770605e2012-02-13 13:51:18 +0000298 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
James Kosin975afc32011-07-14 08:15:06 +0000299 show_post_progress(i, POST_AFTER, POST_FAILED);
300 if (test_flags & POST_CRITICAL)
301 gd->flags |= GD_FLG_POSTFAIL;
302 if (test_flags & POST_STOP)
303 gd->flags |= GD_FLG_POSTSTOP;
304 } else {
305 post_log("PASSED\n");
306 show_post_progress(i, POST_AFTER, POST_PASSED);
307 }
wdenk228f29a2002-12-08 09:53:23 +0000308 }
wdenka042ac82002-09-12 22:36:57 +0000309
Wolfgang Denk50da8372011-10-29 09:42:22 +0000310 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL))
Heiko Schochere92372c2011-10-12 01:18:05 +0000311 post_bootmode_test_off();
wdenka042ac82002-09-12 22:36:57 +0000312
313 return 0;
314 } else {
315 return -1;
316 }
317}
318
Wolfgang Denk50da8372011-10-29 09:42:22 +0000319int post_run(char *name, int flags)
wdenka042ac82002-09-12 22:36:57 +0000320{
321 unsigned int i;
322 int test_flags[POST_MAX_NUMBER];
323
Heiko Schochere92372c2011-10-12 01:18:05 +0000324 post_get_flags(test_flags);
wdenka042ac82002-09-12 22:36:57 +0000325
326 if (name == NULL) {
327 unsigned int last;
328
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200329 if (gd->flags & GD_FLG_POSTSTOP)
330 return 0;
331
Heiko Schochere92372c2011-10-12 01:18:05 +0000332 if (post_bootmode_get(&last) & POST_POWERTEST) {
Yuri Tikhonove262efe2008-02-04 14:11:03 +0100333 if (last & POST_FAIL_SAVE) {
334 last &= ~POST_FAIL_SAVE;
335 gd->flags |= GD_FLG_POSTFAIL;
336 }
wdenka042ac82002-09-12 22:36:57 +0000337 if (last < post_list_size &&
338 (flags & test_flags[last] & POST_ALWAYS) &&
339 (flags & test_flags[last] & POST_MEM)) {
340
Heiko Schochere92372c2011-10-12 01:18:05 +0000341 post_run_single(post_list + last,
wdenkea909b72002-11-21 23:11:29 +0000342 test_flags[last],
343 flags | POST_REBOOT, last);
wdenka042ac82002-09-12 22:36:57 +0000344
345 for (i = last + 1; i < post_list_size; i++) {
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200346 if (gd->flags & GD_FLG_POSTSTOP)
347 break;
Heiko Schochere92372c2011-10-12 01:18:05 +0000348 post_run_single(post_list + i,
wdenkea909b72002-11-21 23:11:29 +0000349 test_flags[i],
350 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000351 }
352 }
353 } else {
354 for (i = 0; i < post_list_size; i++) {
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200355 if (gd->flags & GD_FLG_POSTSTOP)
356 break;
Heiko Schochere92372c2011-10-12 01:18:05 +0000357 post_run_single(post_list + i,
wdenkea909b72002-11-21 23:11:29 +0000358 test_flags[i],
359 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000360 }
361 }
362
363 return 0;
364 } else {
365 for (i = 0; i < post_list_size; i++) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000366 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000367 break;
368 }
369
370 if (i < post_list_size) {
Sascha Laue5744ddc2008-05-30 09:48:14 +0200371 WATCHDOG_RESET();
Heiko Schochere92372c2011-10-12 01:18:05 +0000372 return post_run_single(post_list + i,
wdenka042ac82002-09-12 22:36:57 +0000373 test_flags[i],
374 flags, i);
375 } else {
376 return -1;
377 }
378 }
379}
380
Heiko Schochere92372c2011-10-12 01:18:05 +0000381static int post_info_single(struct post_test *test, int full)
wdenka042ac82002-09-12 22:36:57 +0000382{
383 if (test->flags & POST_MANUAL) {
384 if (full)
Heiko Schochere92372c2011-10-12 01:18:05 +0000385 printf("%s - %s\n"
wdenka042ac82002-09-12 22:36:57 +0000386 " %s\n", test->cmd, test->name, test->desc);
387 else
Heiko Schochere92372c2011-10-12 01:18:05 +0000388 printf(" %-15s - %s\n", test->cmd, test->name);
wdenka042ac82002-09-12 22:36:57 +0000389
390 return 0;
391 } else {
392 return -1;
393 }
394}
395
Wolfgang Denk50da8372011-10-29 09:42:22 +0000396int post_info(char *name)
wdenka042ac82002-09-12 22:36:57 +0000397{
398 unsigned int i;
399
400 if (name == NULL) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000401 for (i = 0; i < post_list_size; i++)
402 post_info_single(post_list + i, 0);
wdenka042ac82002-09-12 22:36:57 +0000403
404 return 0;
405 } else {
406 for (i = 0; i < post_list_size; i++) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000407 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000408 break;
409 }
410
Wolfgang Denk50da8372011-10-29 09:42:22 +0000411 if (i < post_list_size)
Heiko Schochere92372c2011-10-12 01:18:05 +0000412 return post_info_single(post_list + i, 1);
Wolfgang Denk50da8372011-10-29 09:42:22 +0000413 else
wdenka042ac82002-09-12 22:36:57 +0000414 return -1;
wdenka042ac82002-09-12 22:36:57 +0000415 }
416}
417
Heiko Schochere92372c2011-10-12 01:18:05 +0000418int post_log(char *format, ...)
wdenka042ac82002-09-12 22:36:57 +0000419{
420 va_list args;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200421 char printbuffer[CONFIG_SYS_PBSIZE];
wdenka042ac82002-09-12 22:36:57 +0000422
Wolfgang Denk50da8372011-10-29 09:42:22 +0000423 va_start(args, format);
wdenka042ac82002-09-12 22:36:57 +0000424
425 /* For this to work, printbuffer must be larger than
426 * anything we ever want to print.
427 */
Wolfgang Denk4d6402b2011-10-29 09:42:23 +0000428 vsprintf(printbuffer, format, args);
Wolfgang Denk50da8372011-10-29 09:42:22 +0000429 va_end(args);
wdenka042ac82002-09-12 22:36:57 +0000430
wdenk56f94be2002-11-05 16:35:14 +0000431#ifdef CONFIG_LOGBUFFER
wdenk228f29a2002-12-08 09:53:23 +0000432 /* Send to the logbuffer */
Heiko Schochere92372c2011-10-12 01:18:05 +0000433 logbuff_log(printbuffer);
wdenk56f94be2002-11-05 16:35:14 +0000434#else
wdenka042ac82002-09-12 22:36:57 +0000435 /* Send to the stdout file */
Heiko Schochere92372c2011-10-12 01:18:05 +0000436 puts(printbuffer);
wdenk56f94be2002-11-05 16:35:14 +0000437#endif
wdenka042ac82002-09-12 22:36:57 +0000438
439 return 0;
440}
441
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200442#ifdef CONFIG_NEEDS_MANUAL_RELOC
Heiko Schochere92372c2011-10-12 01:18:05 +0000443void post_reloc(void)
wdenka042ac82002-09-12 22:36:57 +0000444{
wdenka042ac82002-09-12 22:36:57 +0000445 unsigned int i;
446
447 /*
448 * We have to relocate the test table manually
449 */
450 for (i = 0; i < post_list_size; i++) {
451 ulong addr;
452 struct post_test *test = post_list + i;
453
454 if (test->name) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000455 addr = (ulong)(test->name) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000456 test->name = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000457 }
458
459 if (test->cmd) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000460 addr = (ulong)(test->cmd) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000461 test->cmd = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000462 }
463
464 if (test->desc) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000465 addr = (ulong)(test->desc) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000466 test->desc = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000467 }
468
469 if (test->test) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000470 addr = (ulong)(test->test) + gd->reloc_off;
wdenka042ac82002-09-12 22:36:57 +0000471 test->test = (int (*)(int flags)) addr;
472 }
wdenk4532cb62003-04-27 22:52:51 +0000473
474 if (test->init_f) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000475 addr = (ulong)(test->init_f) + gd->reloc_off;
wdenk4532cb62003-04-27 22:52:51 +0000476 test->init_f = (int (*)(void)) addr;
477 }
478
479 if (test->reloc) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000480 addr = (ulong)(test->reloc) + gd->reloc_off;
wdenk4532cb62003-04-27 22:52:51 +0000481 test->reloc = (void (*)(void)) addr;
wdenk8bde7f72003-06-27 21:31:46 +0000482
wdenk4532cb62003-04-27 22:52:51 +0000483 test->reloc();
484 }
wdenka042ac82002-09-12 22:36:57 +0000485 }
486}
Peter Tyser521af042009-09-21 11:20:36 -0500487#endif
wdenka042ac82002-09-12 22:36:57 +0000488
wdenk4532cb62003-04-27 22:52:51 +0000489
490/*
491 * Some tests (e.g. SYSMON) need the time when post_init_f started,
492 * but we cannot use get_timer() at this point.
493 *
494 * On PowerPC we implement it using the timebase register.
495 */
Heiko Schochere92372c2011-10-12 01:18:05 +0000496unsigned long post_time_ms(unsigned long base)
wdenk4532cb62003-04-27 22:52:51 +0000497{
Valentin Longchamp4e518b82012-03-30 03:29:28 +0000498#if defined(CONFIG_PPC) || defined(CONFIG_BLACKFIN) || defined(CONFIG_ARM)
Christian Rieschc90a4dd2011-12-09 16:54:02 +0100499 return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ)
Heiko Schochere92372c2011-10-12 01:18:05 +0000500 - base;
wdenk4532cb62003-04-27 22:52:51 +0000501#else
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100502#warning "Not implemented yet"
wdenk4532cb62003-04-27 22:52:51 +0000503 return 0; /* Not implemented yet */
504#endif
505}