blob: 0e67ad74b779039ae73f4f5483528bc7382805de [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-VILLARD2a7a0312009-05-16 12:14:54 +020025#include <stdio_dev.h>
wdenka042ac82002-09-12 22:36:57 +000026#include <watchdog.h>
27#include <post.h>
28
Mike Frysinger2073edd2011-05-10 07:01:21 +000029#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
30#include <asm/gpio.h>
31#endif
32
wdenk56f94be2002-11-05 16:35:14 +000033#ifdef CONFIG_LOGBUFFER
34#include <logbuff.h>
35#endif
36
Wolfgang Denk6405a152006-03-31 18:32:53 +020037DECLARE_GLOBAL_DATA_PTR;
38
wdenka042ac82002-09-12 22:36:57 +000039#define POST_MAX_NUMBER 32
40
41#define BOOTMODE_MAGIC 0xDEAD0000
42
Heiko Schocher51ee5912011-10-12 01:18:05 +000043int post_init_f(void)
wdenkc08f1582003-04-27 22:52:51 +000044{
wdenkc08f1582003-04-27 22:52:51 +000045 int res = 0;
46 unsigned int i;
47
48 for (i = 0; i < post_list_size; i++) {
49 struct post_test *test = post_list + i;
50
Wolfgang Denkf7a49f12011-10-29 09:42:22 +000051 if (test->init_f && test->init_f())
wdenkc08f1582003-04-27 22:52:51 +000052 res = -1;
wdenkc08f1582003-04-27 22:52:51 +000053 }
wdenk57b2d802003-06-27 21:31:46 +000054
wdenkc08f1582003-04-27 22:52:51 +000055 gd->post_init_f_time = post_time_ms(0);
56 if (!gd->post_init_f_time)
Heiko Schocher51ee5912011-10-12 01:18:05 +000057 printf("%s: post_time_ms not implemented\n", __FILE__);
wdenkc08f1582003-04-27 22:52:51 +000058
59 return res;
60}
61
Stefan Roesef0a15c52009-12-03 06:24:30 +010062/*
63 * Supply a default implementation for post_hotkeys_pressed() for boards
64 * without hotkey support. We always return 0 here, so that the
65 * long-running tests won't be started.
66 *
67 * Boards with hotkey support can override this weak default function
68 * by defining one in their board specific code.
69 */
70int __post_hotkeys_pressed(void)
71{
Mike Frysinger2073edd2011-05-10 07:01:21 +000072#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
73 int ret;
74 unsigned gpio = CONFIG_SYS_POST_HOTKEYS_GPIO;
75
76 ret = gpio_request(gpio, "hotkeys");
77 if (ret) {
78 printf("POST: gpio hotkey request failed\n");
79 return 0;
80 }
81
82 gpio_direction_input(gpio);
83 ret = gpio_get_value(gpio);
84 gpio_free(gpio);
85
86 return ret;
87#endif
88
Stefan Roesef0a15c52009-12-03 06:24:30 +010089 return 0; /* No hotkeys supported */
90}
91int post_hotkeys_pressed(void)
92 __attribute__((weak, alias("__post_hotkeys_pressed")));
93
94
Heiko Schocher51ee5912011-10-12 01:18:05 +000095void post_bootmode_init(void)
wdenka042ac82002-09-12 22:36:57 +000096{
Heiko Schocher51ee5912011-10-12 01:18:05 +000097 int bootmode = post_bootmode_get(0);
wdenk874ac262003-07-24 23:38:38 +000098 int newword;
wdenk9c53f402003-10-15 23:53:47 +000099
Heiko Schocher51ee5912011-10-12 01:18:05 +0000100 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST))
wdenk874ac262003-07-24 23:38:38 +0000101 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000102 else if (bootmode == 0)
wdenk874ac262003-07-24 23:38:38 +0000103 newword = BOOTMODE_MAGIC | POST_POWERON;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000104 else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST)
wdenk874ac262003-07-24 23:38:38 +0000105 newword = BOOTMODE_MAGIC | POST_NORMAL;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000106 else
wdenk874ac262003-07-24 23:38:38 +0000107 /* Use old value */
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000108 newword = post_word_load() & ~POST_COLDBOOT;
wdenk874ac262003-07-24 23:38:38 +0000109
110 if (bootmode == 0)
wdenk874ac262003-07-24 23:38:38 +0000111 /* We are booting after power-on */
112 newword |= POST_COLDBOOT;
wdenka042ac82002-09-12 22:36:57 +0000113
Heiko Schocher51ee5912011-10-12 01:18:05 +0000114 post_word_store(newword);
wdenk874ac262003-07-24 23:38:38 +0000115
wdenk9dfa8d12002-12-08 09:53:23 +0000116 /* Reset activity record */
117 gd->post_log_word = 0;
Valentin Longchampb9181732011-08-03 02:37:01 +0000118 gd->post_log_res = 0;
wdenka042ac82002-09-12 22:36:57 +0000119}
120
Heiko Schocher51ee5912011-10-12 01:18:05 +0000121int post_bootmode_get(unsigned int *last_test)
wdenka042ac82002-09-12 22:36:57 +0000122{
Heiko Schocher51ee5912011-10-12 01:18:05 +0000123 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000124 int bootmode;
125
Heiko Schocher51ee5912011-10-12 01:18:05 +0000126 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC)
wdenka042ac82002-09-12 22:36:57 +0000127 return 0;
wdenka042ac82002-09-12 22:36:57 +0000128
wdenk874ac262003-07-24 23:38:38 +0000129 bootmode = word & 0x7F;
wdenka042ac82002-09-12 22:36:57 +0000130
Heiko Schocher51ee5912011-10-12 01:18:05 +0000131 if (last_test && (bootmode & POST_POWERTEST))
wdenka042ac82002-09-12 22:36:57 +0000132 *last_test = (word >> 8) & 0xFF;
wdenka042ac82002-09-12 22:36:57 +0000133
134 return bootmode;
135}
136
wdenk9dfa8d12002-12-08 09:53:23 +0000137/* POST tests run before relocation only mark status bits .... */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000138static void post_log_mark_start(unsigned long testid)
wdenk9dfa8d12002-12-08 09:53:23 +0000139{
Valentin Longchampb9181732011-08-03 02:37:01 +0000140 gd->post_log_word |= testid;
wdenk9dfa8d12002-12-08 09:53:23 +0000141}
142
Heiko Schocher51ee5912011-10-12 01:18:05 +0000143static void post_log_mark_succ(unsigned long testid)
wdenk9dfa8d12002-12-08 09:53:23 +0000144{
Valentin Longchampb9181732011-08-03 02:37:01 +0000145 gd->post_log_res |= testid;
wdenk9dfa8d12002-12-08 09:53:23 +0000146}
147
148/* ... and the messages are output once we are relocated */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000149void post_output_backlog(void)
wdenk9dfa8d12002-12-08 09:53:23 +0000150{
wdenk9dfa8d12002-12-08 09:53:23 +0000151 int j;
152
153 for (j = 0; j < post_list_size; j++) {
Valentin Longchampb9181732011-08-03 02:37:01 +0000154 if (gd->post_log_word & (post_list[j].testid)) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000155 post_log("POST %s ", post_list[j].cmd);
Valentin Longchampb9181732011-08-03 02:37:01 +0000156 if (gd->post_log_res & post_list[j].testid)
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000157 post_log("PASSED\n");
wdenke97d3d92004-02-23 22:22:28 +0000158 else {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000159 post_log("FAILED\n");
160 show_boot_progress(-31);
wdenke97d3d92004-02-23 22:22:28 +0000161 }
wdenk9dfa8d12002-12-08 09:53:23 +0000162 }
163 }
164}
165
Heiko Schocher51ee5912011-10-12 01:18:05 +0000166static void post_bootmode_test_on(unsigned int last_test)
wdenka042ac82002-09-12 22:36:57 +0000167{
Heiko Schocher51ee5912011-10-12 01:18:05 +0000168 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000169
170 word |= POST_POWERTEST;
171
172 word |= (last_test & 0xFF) << 8;
173
Heiko Schocher51ee5912011-10-12 01:18:05 +0000174 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000175}
176
Heiko Schocher51ee5912011-10-12 01:18:05 +0000177static void post_bootmode_test_off(void)
wdenka042ac82002-09-12 22:36:57 +0000178{
Heiko Schocher51ee5912011-10-12 01:18:05 +0000179 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000180
181 word &= ~POST_POWERTEST;
182
Heiko Schocher51ee5912011-10-12 01:18:05 +0000183 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000184}
185
Valentin Longchampcfc88802011-08-03 02:37:02 +0000186#ifndef CONFIG_POST_SKIP_ENV_FLAGS
187static void post_get_env_flags(int *test_flags)
wdenka042ac82002-09-12 22:36:57 +0000188{
Yuri Tikhonov6a068a12008-02-04 14:11:03 +0100189 int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST,
190 POST_CRITICAL };
191 char *var[] = { "post_poweron", "post_normal", "post_slowtest",
192 "post_critical" };
Mike Frysinger83a687b2011-05-10 07:28:35 +0000193 int varnum = ARRAY_SIZE(var);
wdenka042ac82002-09-12 22:36:57 +0000194 char list[128]; /* long enough for POST list */
195 char *name;
196 char *s;
197 int last;
198 int i, j;
199
wdenka042ac82002-09-12 22:36:57 +0000200 for (i = 0; i < varnum; i++) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000201 if (getenv_f(var[i], list, sizeof(list)) <= 0)
wdenka042ac82002-09-12 22:36:57 +0000202 continue;
203
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000204 for (j = 0; j < post_list_size; j++)
wdenka042ac82002-09-12 22:36:57 +0000205 test_flags[j] &= ~flag[i];
wdenka042ac82002-09-12 22:36:57 +0000206
207 last = 0;
208 name = list;
209 while (!last) {
210 while (*name && *name == ' ')
211 name++;
212 if (*name == 0)
213 break;
214 s = name + 1;
215 while (*s && *s != ' ')
216 s++;
217 if (*s == 0)
218 last = 1;
219 else
220 *s = 0;
221
222 for (j = 0; j < post_list_size; j++) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000223 if (strcmp(post_list[j].cmd, name) == 0) {
wdenka042ac82002-09-12 22:36:57 +0000224 test_flags[j] |= flag[i];
225 break;
226 }
227 }
228
Heiko Schocher51ee5912011-10-12 01:18:05 +0000229 if (j == post_list_size)
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000230 printf("No such test: %s\n", name);
wdenka042ac82002-09-12 22:36:57 +0000231
232 name = s + 1;
233 }
234 }
Valentin Longchampcfc88802011-08-03 02:37:02 +0000235}
236#endif
237
238static void post_get_flags(int *test_flags)
239{
240 int j;
241
242 for (j = 0; j < post_list_size; j++)
243 test_flags[j] = post_list[j].flags;
244
245#ifndef CONFIG_POST_SKIP_ENV_FLAGS
246 post_get_env_flags(test_flags);
247#endif
wdenkca9bc762003-07-15 07:45:49 +0000248
Heiko Schocher51ee5912011-10-12 01:18:05 +0000249 for (j = 0; j < post_list_size; j++)
250 if (test_flags[j] & POST_POWERON)
wdenkca9bc762003-07-15 07:45:49 +0000251 test_flags[j] |= POST_SLOWTEST;
wdenka042ac82002-09-12 22:36:57 +0000252}
253
Heiko Schocher51ee5912011-10-12 01:18:05 +0000254void __show_post_progress(unsigned int test_num, int before, int result)
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200255{
256}
Heiko Schocher51ee5912011-10-12 01:18:05 +0000257void show_post_progress(unsigned int, int, int)
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200258 __attribute__((weak, alias("__show_post_progress")));
259
Heiko Schocher51ee5912011-10-12 01:18:05 +0000260static int post_run_single(struct post_test *test,
wdenka042ac82002-09-12 22:36:57 +0000261 int test_flags, int flags, unsigned int i)
262{
263 if ((flags & test_flags & POST_ALWAYS) &&
264 (flags & test_flags & POST_MEM)) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000265 WATCHDOG_RESET();
wdenka042ac82002-09-12 22:36:57 +0000266
267 if (!(flags & POST_REBOOT)) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000268 if ((test_flags & POST_REBOOT) &&
269 !(flags & POST_MANUAL)) {
270 post_bootmode_test_on(
Yuri Tikhonov6a068a12008-02-04 14:11:03 +0100271 (gd->flags & GD_FLG_POSTFAIL) ?
272 POST_FAIL_SAVE | i : i);
wdenka042ac82002-09-12 22:36:57 +0000273 }
274
wdenk9dfa8d12002-12-08 09:53:23 +0000275 if (test_flags & POST_PREREL)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000276 post_log_mark_start(test->testid);
wdenk9dfa8d12002-12-08 09:53:23 +0000277 else
Heiko Schocher51ee5912011-10-12 01:18:05 +0000278 post_log("POST %s ", test->cmd);
wdenka042ac82002-09-12 22:36:57 +0000279 }
280
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200281 show_post_progress(i, POST_BEFORE, POST_FAILED);
282
wdenk9dfa8d12002-12-08 09:53:23 +0000283 if (test_flags & POST_PREREL) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000284 if ((*test->test)(flags) == 0) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000285 post_log_mark_succ(test->testid);
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200286 show_post_progress(i, POST_AFTER, POST_PASSED);
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000287 } else {
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200288 show_post_progress(i, POST_AFTER, POST_FAILED);
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200289 if (test_flags & POST_CRITICAL)
290 gd->flags |= GD_FLG_POSTFAIL;
291 if (test_flags & POST_STOP)
292 gd->flags |= GD_FLG_POSTSTOP;
293 }
wdenk9dfa8d12002-12-08 09:53:23 +0000294 } else {
James Kosine7deffc2011-07-14 08:15:06 +0000295 if ((*test->test)(flags) != 0) {
296 post_log("FAILED\n");
297 show_boot_progress(-32);
298 show_post_progress(i, POST_AFTER, POST_FAILED);
299 if (test_flags & POST_CRITICAL)
300 gd->flags |= GD_FLG_POSTFAIL;
301 if (test_flags & POST_STOP)
302 gd->flags |= GD_FLG_POSTSTOP;
303 } else {
304 post_log("PASSED\n");
305 show_post_progress(i, POST_AFTER, POST_PASSED);
306 }
wdenk9dfa8d12002-12-08 09:53:23 +0000307 }
wdenka042ac82002-09-12 22:36:57 +0000308
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000309 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL))
Heiko Schocher51ee5912011-10-12 01:18:05 +0000310 post_bootmode_test_off();
wdenka042ac82002-09-12 22:36:57 +0000311
312 return 0;
313 } else {
314 return -1;
315 }
316}
317
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000318int post_run(char *name, int flags)
wdenka042ac82002-09-12 22:36:57 +0000319{
320 unsigned int i;
321 int test_flags[POST_MAX_NUMBER];
322
Heiko Schocher51ee5912011-10-12 01:18:05 +0000323 post_get_flags(test_flags);
wdenka042ac82002-09-12 22:36:57 +0000324
325 if (name == NULL) {
326 unsigned int last;
327
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200328 if (gd->flags & GD_FLG_POSTSTOP)
329 return 0;
330
Heiko Schocher51ee5912011-10-12 01:18:05 +0000331 if (post_bootmode_get(&last) & POST_POWERTEST) {
Yuri Tikhonov6a068a12008-02-04 14:11:03 +0100332 if (last & POST_FAIL_SAVE) {
333 last &= ~POST_FAIL_SAVE;
334 gd->flags |= GD_FLG_POSTFAIL;
335 }
wdenka042ac82002-09-12 22:36:57 +0000336 if (last < post_list_size &&
337 (flags & test_flags[last] & POST_ALWAYS) &&
338 (flags & test_flags[last] & POST_MEM)) {
339
Heiko Schocher51ee5912011-10-12 01:18:05 +0000340 post_run_single(post_list + last,
wdenk2029f4d2002-11-21 23:11:29 +0000341 test_flags[last],
342 flags | POST_REBOOT, last);
wdenka042ac82002-09-12 22:36:57 +0000343
344 for (i = last + 1; i < post_list_size; i++) {
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200345 if (gd->flags & GD_FLG_POSTSTOP)
346 break;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000347 post_run_single(post_list + i,
wdenk2029f4d2002-11-21 23:11:29 +0000348 test_flags[i],
349 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000350 }
351 }
352 } else {
353 for (i = 0; i < post_list_size; i++) {
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200354 if (gd->flags & GD_FLG_POSTSTOP)
355 break;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000356 post_run_single(post_list + i,
wdenk2029f4d2002-11-21 23:11:29 +0000357 test_flags[i],
358 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000359 }
360 }
361
362 return 0;
363 } else {
364 for (i = 0; i < post_list_size; i++) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000365 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000366 break;
367 }
368
369 if (i < post_list_size) {
Sascha Laue00150532008-05-30 09:48:14 +0200370 WATCHDOG_RESET();
Heiko Schocher51ee5912011-10-12 01:18:05 +0000371 return post_run_single(post_list + i,
wdenka042ac82002-09-12 22:36:57 +0000372 test_flags[i],
373 flags, i);
374 } else {
375 return -1;
376 }
377 }
378}
379
Heiko Schocher51ee5912011-10-12 01:18:05 +0000380static int post_info_single(struct post_test *test, int full)
wdenka042ac82002-09-12 22:36:57 +0000381{
382 if (test->flags & POST_MANUAL) {
383 if (full)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000384 printf("%s - %s\n"
wdenka042ac82002-09-12 22:36:57 +0000385 " %s\n", test->cmd, test->name, test->desc);
386 else
Heiko Schocher51ee5912011-10-12 01:18:05 +0000387 printf(" %-15s - %s\n", test->cmd, test->name);
wdenka042ac82002-09-12 22:36:57 +0000388
389 return 0;
390 } else {
391 return -1;
392 }
393}
394
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000395int post_info(char *name)
wdenka042ac82002-09-12 22:36:57 +0000396{
397 unsigned int i;
398
399 if (name == NULL) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000400 for (i = 0; i < post_list_size; i++)
401 post_info_single(post_list + i, 0);
wdenka042ac82002-09-12 22:36:57 +0000402
403 return 0;
404 } else {
405 for (i = 0; i < post_list_size; i++) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000406 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000407 break;
408 }
409
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000410 if (i < post_list_size)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000411 return post_info_single(post_list + i, 1);
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000412 else
wdenka042ac82002-09-12 22:36:57 +0000413 return -1;
wdenka042ac82002-09-12 22:36:57 +0000414 }
415}
416
Heiko Schocher51ee5912011-10-12 01:18:05 +0000417int post_log(char *format, ...)
wdenka042ac82002-09-12 22:36:57 +0000418{
419 va_list args;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200420 char printbuffer[CONFIG_SYS_PBSIZE];
wdenka042ac82002-09-12 22:36:57 +0000421
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000422 va_start(args, format);
wdenka042ac82002-09-12 22:36:57 +0000423
424 /* For this to work, printbuffer must be larger than
425 * anything we ever want to print.
426 */
Wolfgang Denkbedfa0a2011-10-29 09:42:23 +0000427 vsprintf(printbuffer, format, args);
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000428 va_end(args);
wdenka042ac82002-09-12 22:36:57 +0000429
wdenk56f94be2002-11-05 16:35:14 +0000430#ifdef CONFIG_LOGBUFFER
wdenk9dfa8d12002-12-08 09:53:23 +0000431 /* Send to the logbuffer */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000432 logbuff_log(printbuffer);
wdenk56f94be2002-11-05 16:35:14 +0000433#else
wdenka042ac82002-09-12 22:36:57 +0000434 /* Send to the stdout file */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000435 puts(printbuffer);
wdenk56f94be2002-11-05 16:35:14 +0000436#endif
wdenka042ac82002-09-12 22:36:57 +0000437
438 return 0;
439}
440
Wolfgang Denkd0813e52010-10-28 20:00:11 +0200441#ifdef CONFIG_NEEDS_MANUAL_RELOC
Heiko Schocher51ee5912011-10-12 01:18:05 +0000442void post_reloc(void)
wdenka042ac82002-09-12 22:36:57 +0000443{
wdenka042ac82002-09-12 22:36:57 +0000444 unsigned int i;
445
446 /*
447 * We have to relocate the test table manually
448 */
449 for (i = 0; i < post_list_size; i++) {
450 ulong addr;
451 struct post_test *test = post_list + i;
452
453 if (test->name) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000454 addr = (ulong)(test->name) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000455 test->name = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000456 }
457
458 if (test->cmd) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000459 addr = (ulong)(test->cmd) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000460 test->cmd = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000461 }
462
463 if (test->desc) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000464 addr = (ulong)(test->desc) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000465 test->desc = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000466 }
467
468 if (test->test) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000469 addr = (ulong)(test->test) + gd->reloc_off;
wdenka042ac82002-09-12 22:36:57 +0000470 test->test = (int (*)(int flags)) addr;
471 }
wdenkc08f1582003-04-27 22:52:51 +0000472
473 if (test->init_f) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000474 addr = (ulong)(test->init_f) + gd->reloc_off;
wdenkc08f1582003-04-27 22:52:51 +0000475 test->init_f = (int (*)(void)) addr;
476 }
477
478 if (test->reloc) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000479 addr = (ulong)(test->reloc) + gd->reloc_off;
wdenkc08f1582003-04-27 22:52:51 +0000480 test->reloc = (void (*)(void)) addr;
wdenk57b2d802003-06-27 21:31:46 +0000481
wdenkc08f1582003-04-27 22:52:51 +0000482 test->reloc();
483 }
wdenka042ac82002-09-12 22:36:57 +0000484 }
485}
Peter Tyser9057cbf2009-09-21 11:20:36 -0500486#endif
wdenka042ac82002-09-12 22:36:57 +0000487
wdenkc08f1582003-04-27 22:52:51 +0000488
489/*
490 * Some tests (e.g. SYSMON) need the time when post_init_f started,
491 * but we cannot use get_timer() at this point.
492 *
493 * On PowerPC we implement it using the timebase register.
494 */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000495unsigned long post_time_ms(unsigned long base)
wdenkc08f1582003-04-27 22:52:51 +0000496{
Heiko Schocherd642b192011-09-14 19:34:33 +0000497#if defined(CONFIG_PPC) || defined(CONFIG_ARM)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000498 return (unsigned long)(get_ticks() / (get_tbclk() / CONFIG_SYS_HZ))
499 - base;
wdenkc08f1582003-04-27 22:52:51 +0000500#else
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100501#warning "Not implemented yet"
wdenkc08f1582003-04-27 22:52:51 +0000502 return 0; /* Not implemented yet */
503#endif
504}