blob: dc9c0f2cf89068b386645b3b9fb22242f287238d [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
51 if (test->init_f && test->init_f()) {
52 res = -1;
53 }
54 }
wdenk57b2d802003-06-27 21:31:46 +000055
wdenkc08f1582003-04-27 22:52:51 +000056 gd->post_init_f_time = post_time_ms(0);
57 if (!gd->post_init_f_time)
Heiko Schocher51ee5912011-10-12 01:18:05 +000058 printf("%s: post_time_ms not implemented\n", __FILE__);
wdenkc08f1582003-04-27 22:52:51 +000059
60 return res;
61}
62
Stefan Roesef0a15c52009-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 Frysinger2073edd2011-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 Roesef0a15c52009-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 Schocher51ee5912011-10-12 01:18:05 +000096void post_bootmode_init(void)
wdenka042ac82002-09-12 22:36:57 +000097{
Heiko Schocher51ee5912011-10-12 01:18:05 +000098 int bootmode = post_bootmode_get(0);
wdenk874ac262003-07-24 23:38:38 +000099 int newword;
wdenk9c53f402003-10-15 23:53:47 +0000100
Heiko Schocher51ee5912011-10-12 01:18:05 +0000101 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST))
wdenk874ac262003-07-24 23:38:38 +0000102 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000103 else if (bootmode == 0)
wdenk874ac262003-07-24 23:38:38 +0000104 newword = BOOTMODE_MAGIC | POST_POWERON;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000105 else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST)
wdenk874ac262003-07-24 23:38:38 +0000106 newword = BOOTMODE_MAGIC | POST_NORMAL;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000107 else
wdenk874ac262003-07-24 23:38:38 +0000108 /* Use old value */
109 newword = post_word_load () & ~POST_COLDBOOT;
wdenk874ac262003-07-24 23:38:38 +0000110
111 if (bootmode == 0)
wdenk874ac262003-07-24 23:38:38 +0000112 /* We are booting after power-on */
113 newword |= POST_COLDBOOT;
wdenka042ac82002-09-12 22:36:57 +0000114
Heiko Schocher51ee5912011-10-12 01:18:05 +0000115 post_word_store(newword);
wdenk874ac262003-07-24 23:38:38 +0000116
wdenk9dfa8d12002-12-08 09:53:23 +0000117 /* Reset activity record */
118 gd->post_log_word = 0;
Valentin Longchampb9181732011-08-03 02:37:01 +0000119 gd->post_log_res = 0;
wdenka042ac82002-09-12 22:36:57 +0000120}
121
Heiko Schocher51ee5912011-10-12 01:18:05 +0000122int post_bootmode_get(unsigned int *last_test)
wdenka042ac82002-09-12 22:36:57 +0000123{
Heiko Schocher51ee5912011-10-12 01:18:05 +0000124 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000125 int bootmode;
126
Heiko Schocher51ee5912011-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
wdenk874ac262003-07-24 23:38:38 +0000130 bootmode = word & 0x7F;
wdenka042ac82002-09-12 22:36:57 +0000131
Heiko Schocher51ee5912011-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
wdenk9dfa8d12002-12-08 09:53:23 +0000138/* POST tests run before relocation only mark status bits .... */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000139static void post_log_mark_start(unsigned long testid)
wdenk9dfa8d12002-12-08 09:53:23 +0000140{
Valentin Longchampb9181732011-08-03 02:37:01 +0000141 gd->post_log_word |= testid;
wdenk9dfa8d12002-12-08 09:53:23 +0000142}
143
Heiko Schocher51ee5912011-10-12 01:18:05 +0000144static void post_log_mark_succ(unsigned long testid)
wdenk9dfa8d12002-12-08 09:53:23 +0000145{
Valentin Longchampb9181732011-08-03 02:37:01 +0000146 gd->post_log_res |= testid;
wdenk9dfa8d12002-12-08 09:53:23 +0000147}
148
149/* ... and the messages are output once we are relocated */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000150void post_output_backlog(void)
wdenk9dfa8d12002-12-08 09:53:23 +0000151{
wdenk9dfa8d12002-12-08 09:53:23 +0000152 int j;
153
154 for (j = 0; j < post_list_size; j++) {
Valentin Longchampb9181732011-08-03 02:37:01 +0000155 if (gd->post_log_word & (post_list[j].testid)) {
wdenk9dfa8d12002-12-08 09:53:23 +0000156 post_log ("POST %s ", post_list[j].cmd);
Valentin Longchampb9181732011-08-03 02:37:01 +0000157 if (gd->post_log_res & post_list[j].testid)
wdenk9dfa8d12002-12-08 09:53:23 +0000158 post_log ("PASSED\n");
wdenke97d3d92004-02-23 22:22:28 +0000159 else {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000160 post_log("FAILED\n");
161 show_boot_progress(-31);
wdenke97d3d92004-02-23 22:22:28 +0000162 }
wdenk9dfa8d12002-12-08 09:53:23 +0000163 }
164 }
165}
166
Heiko Schocher51ee5912011-10-12 01:18:05 +0000167static void post_bootmode_test_on(unsigned int last_test)
wdenka042ac82002-09-12 22:36:57 +0000168{
Heiko Schocher51ee5912011-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 Schocher51ee5912011-10-12 01:18:05 +0000175 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000176}
177
Heiko Schocher51ee5912011-10-12 01:18:05 +0000178static void post_bootmode_test_off(void)
wdenka042ac82002-09-12 22:36:57 +0000179{
Heiko Schocher51ee5912011-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 Schocher51ee5912011-10-12 01:18:05 +0000184 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000185}
186
Valentin Longchampcfc88802011-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 Tikhonov6a068a12008-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 Frysinger83a687b2011-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 Denk76af2782010-07-24 21:55:43 +0200202 if (getenv_f(var[i], list, sizeof (list)) <= 0)
wdenka042ac82002-09-12 22:36:57 +0000203 continue;
204
205 for (j = 0; j < post_list_size; j++) {
206 test_flags[j] &= ~flag[i];
207 }
208
209 last = 0;
210 name = list;
211 while (!last) {
212 while (*name && *name == ' ')
213 name++;
214 if (*name == 0)
215 break;
216 s = name + 1;
217 while (*s && *s != ' ')
218 s++;
219 if (*s == 0)
220 last = 1;
221 else
222 *s = 0;
223
224 for (j = 0; j < post_list_size; j++) {
225 if (strcmp (post_list[j].cmd, name) == 0) {
226 test_flags[j] |= flag[i];
227 break;
228 }
229 }
230
Heiko Schocher51ee5912011-10-12 01:18:05 +0000231 if (j == post_list_size)
wdenka042ac82002-09-12 22:36:57 +0000232 printf ("No such test: %s\n", name);
wdenka042ac82002-09-12 22:36:57 +0000233
234 name = s + 1;
235 }
236 }
Valentin Longchampcfc88802011-08-03 02:37:02 +0000237}
238#endif
239
240static void post_get_flags(int *test_flags)
241{
242 int j;
243
244 for (j = 0; j < post_list_size; j++)
245 test_flags[j] = post_list[j].flags;
246
247#ifndef CONFIG_POST_SKIP_ENV_FLAGS
248 post_get_env_flags(test_flags);
249#endif
wdenkca9bc762003-07-15 07:45:49 +0000250
Heiko Schocher51ee5912011-10-12 01:18:05 +0000251 for (j = 0; j < post_list_size; j++)
252 if (test_flags[j] & POST_POWERON)
wdenkca9bc762003-07-15 07:45:49 +0000253 test_flags[j] |= POST_SLOWTEST;
wdenka042ac82002-09-12 22:36:57 +0000254}
255
Heiko Schocher51ee5912011-10-12 01:18:05 +0000256void __show_post_progress(unsigned int test_num, int before, int result)
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200257{
258}
Heiko Schocher51ee5912011-10-12 01:18:05 +0000259void show_post_progress(unsigned int, int, int)
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200260 __attribute__((weak, alias("__show_post_progress")));
261
Heiko Schocher51ee5912011-10-12 01:18:05 +0000262static int post_run_single(struct post_test *test,
wdenka042ac82002-09-12 22:36:57 +0000263 int test_flags, int flags, unsigned int i)
264{
265 if ((flags & test_flags & POST_ALWAYS) &&
266 (flags & test_flags & POST_MEM)) {
267 WATCHDOG_RESET ();
268
269 if (!(flags & POST_REBOOT)) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000270 if ((test_flags & POST_REBOOT) &&
271 !(flags & POST_MANUAL)) {
272 post_bootmode_test_on(
Yuri Tikhonov6a068a12008-02-04 14:11:03 +0100273 (gd->flags & GD_FLG_POSTFAIL) ?
274 POST_FAIL_SAVE | i : i);
wdenka042ac82002-09-12 22:36:57 +0000275 }
276
wdenk9dfa8d12002-12-08 09:53:23 +0000277 if (test_flags & POST_PREREL)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000278 post_log_mark_start(test->testid);
wdenk9dfa8d12002-12-08 09:53:23 +0000279 else
Heiko Schocher51ee5912011-10-12 01:18:05 +0000280 post_log("POST %s ", test->cmd);
wdenka042ac82002-09-12 22:36:57 +0000281 }
282
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200283 show_post_progress(i, POST_BEFORE, POST_FAILED);
284
wdenk9dfa8d12002-12-08 09:53:23 +0000285 if (test_flags & POST_PREREL) {
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200286 if ((*test->test) (flags) == 0) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000287 post_log_mark_succ(test->testid);
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200288 show_post_progress(i, POST_AFTER, POST_PASSED);
289 }
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200290 else {
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200291 show_post_progress(i, POST_AFTER, POST_FAILED);
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200292 if (test_flags & POST_CRITICAL)
293 gd->flags |= GD_FLG_POSTFAIL;
294 if (test_flags & POST_STOP)
295 gd->flags |= GD_FLG_POSTSTOP;
296 }
wdenk9dfa8d12002-12-08 09:53:23 +0000297 } else {
James Kosine7deffc2011-07-14 08:15:06 +0000298 if ((*test->test)(flags) != 0) {
299 post_log("FAILED\n");
300 show_boot_progress(-32);
301 show_post_progress(i, POST_AFTER, POST_FAILED);
302 if (test_flags & POST_CRITICAL)
303 gd->flags |= GD_FLG_POSTFAIL;
304 if (test_flags & POST_STOP)
305 gd->flags |= GD_FLG_POSTSTOP;
306 } else {
307 post_log("PASSED\n");
308 show_post_progress(i, POST_AFTER, POST_PASSED);
309 }
wdenk9dfa8d12002-12-08 09:53:23 +0000310 }
wdenka042ac82002-09-12 22:36:57 +0000311
312 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000313 post_bootmode_test_off();
wdenka042ac82002-09-12 22:36:57 +0000314 }
315
316 return 0;
317 } else {
318 return -1;
319 }
320}
321
322int post_run (char *name, int flags)
323{
324 unsigned int i;
325 int test_flags[POST_MAX_NUMBER];
326
Heiko Schocher51ee5912011-10-12 01:18:05 +0000327 post_get_flags(test_flags);
wdenka042ac82002-09-12 22:36:57 +0000328
329 if (name == NULL) {
330 unsigned int last;
331
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200332 if (gd->flags & GD_FLG_POSTSTOP)
333 return 0;
334
Heiko Schocher51ee5912011-10-12 01:18:05 +0000335 if (post_bootmode_get(&last) & POST_POWERTEST) {
Yuri Tikhonov6a068a12008-02-04 14:11:03 +0100336 if (last & POST_FAIL_SAVE) {
337 last &= ~POST_FAIL_SAVE;
338 gd->flags |= GD_FLG_POSTFAIL;
339 }
wdenka042ac82002-09-12 22:36:57 +0000340 if (last < post_list_size &&
341 (flags & test_flags[last] & POST_ALWAYS) &&
342 (flags & test_flags[last] & POST_MEM)) {
343
Heiko Schocher51ee5912011-10-12 01:18:05 +0000344 post_run_single(post_list + last,
wdenk2029f4d2002-11-21 23:11:29 +0000345 test_flags[last],
346 flags | POST_REBOOT, last);
wdenka042ac82002-09-12 22:36:57 +0000347
348 for (i = last + 1; i < post_list_size; i++) {
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200349 if (gd->flags & GD_FLG_POSTSTOP)
350 break;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000351 post_run_single(post_list + i,
wdenk2029f4d2002-11-21 23:11:29 +0000352 test_flags[i],
353 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000354 }
355 }
356 } else {
357 for (i = 0; i < post_list_size; i++) {
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200358 if (gd->flags & GD_FLG_POSTSTOP)
359 break;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000360 post_run_single(post_list + i,
wdenk2029f4d2002-11-21 23:11:29 +0000361 test_flags[i],
362 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000363 }
364 }
365
366 return 0;
367 } else {
368 for (i = 0; i < post_list_size; i++) {
369 if (strcmp (post_list[i].cmd, name) == 0)
370 break;
371 }
372
373 if (i < post_list_size) {
Sascha Laue00150532008-05-30 09:48:14 +0200374 WATCHDOG_RESET();
Heiko Schocher51ee5912011-10-12 01:18:05 +0000375 return post_run_single(post_list + i,
wdenka042ac82002-09-12 22:36:57 +0000376 test_flags[i],
377 flags, i);
378 } else {
379 return -1;
380 }
381 }
382}
383
Heiko Schocher51ee5912011-10-12 01:18:05 +0000384static int post_info_single(struct post_test *test, int full)
wdenka042ac82002-09-12 22:36:57 +0000385{
386 if (test->flags & POST_MANUAL) {
387 if (full)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000388 printf("%s - %s\n"
wdenka042ac82002-09-12 22:36:57 +0000389 " %s\n", test->cmd, test->name, test->desc);
390 else
Heiko Schocher51ee5912011-10-12 01:18:05 +0000391 printf(" %-15s - %s\n", test->cmd, test->name);
wdenka042ac82002-09-12 22:36:57 +0000392
393 return 0;
394 } else {
395 return -1;
396 }
397}
398
399int post_info (char *name)
400{
401 unsigned int i;
402
403 if (name == NULL) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000404 for (i = 0; i < post_list_size; i++)
405 post_info_single(post_list + i, 0);
wdenka042ac82002-09-12 22:36:57 +0000406
407 return 0;
408 } else {
409 for (i = 0; i < post_list_size; i++) {
410 if (strcmp (post_list[i].cmd, name) == 0)
411 break;
412 }
413
414 if (i < post_list_size) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000415 return post_info_single(post_list + i, 1);
wdenka042ac82002-09-12 22:36:57 +0000416 } else {
417 return -1;
418 }
419 }
420}
421
Heiko Schocher51ee5912011-10-12 01:18:05 +0000422int post_log(char *format, ...)
wdenka042ac82002-09-12 22:36:57 +0000423{
424 va_list args;
425 uint i;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200426 char printbuffer[CONFIG_SYS_PBSIZE];
wdenka042ac82002-09-12 22:36:57 +0000427
428 va_start (args, format);
429
430 /* For this to work, printbuffer must be larger than
431 * anything we ever want to print.
432 */
433 i = vsprintf (printbuffer, format, args);
434 va_end (args);
435
wdenk56f94be2002-11-05 16:35:14 +0000436#ifdef CONFIG_LOGBUFFER
wdenk9dfa8d12002-12-08 09:53:23 +0000437 /* Send to the logbuffer */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000438 logbuff_log(printbuffer);
wdenk56f94be2002-11-05 16:35:14 +0000439#else
wdenka042ac82002-09-12 22:36:57 +0000440 /* Send to the stdout file */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000441 puts(printbuffer);
wdenk56f94be2002-11-05 16:35:14 +0000442#endif
wdenka042ac82002-09-12 22:36:57 +0000443
444 return 0;
445}
446
Wolfgang Denkd0813e52010-10-28 20:00:11 +0200447#ifdef CONFIG_NEEDS_MANUAL_RELOC
Heiko Schocher51ee5912011-10-12 01:18:05 +0000448void post_reloc(void)
wdenka042ac82002-09-12 22:36:57 +0000449{
wdenka042ac82002-09-12 22:36:57 +0000450 unsigned int i;
451
452 /*
453 * We have to relocate the test table manually
454 */
455 for (i = 0; i < post_list_size; i++) {
456 ulong addr;
457 struct post_test *test = post_list + i;
458
459 if (test->name) {
460 addr = (ulong) (test->name) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000461 test->name = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000462 }
463
464 if (test->cmd) {
465 addr = (ulong) (test->cmd) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000466 test->cmd = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000467 }
468
469 if (test->desc) {
470 addr = (ulong) (test->desc) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000471 test->desc = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000472 }
473
474 if (test->test) {
475 addr = (ulong) (test->test) + gd->reloc_off;
476 test->test = (int (*)(int flags)) addr;
477 }
wdenkc08f1582003-04-27 22:52:51 +0000478
479 if (test->init_f) {
480 addr = (ulong) (test->init_f) + gd->reloc_off;
481 test->init_f = (int (*)(void)) addr;
482 }
483
484 if (test->reloc) {
485 addr = (ulong) (test->reloc) + gd->reloc_off;
486 test->reloc = (void (*)(void)) addr;
wdenk57b2d802003-06-27 21:31:46 +0000487
wdenkc08f1582003-04-27 22:52:51 +0000488 test->reloc();
489 }
wdenka042ac82002-09-12 22:36:57 +0000490 }
491}
Peter Tyser9057cbf2009-09-21 11:20:36 -0500492#endif
wdenka042ac82002-09-12 22:36:57 +0000493
wdenkc08f1582003-04-27 22:52:51 +0000494
495/*
496 * Some tests (e.g. SYSMON) need the time when post_init_f started,
497 * but we cannot use get_timer() at this point.
498 *
499 * On PowerPC we implement it using the timebase register.
500 */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000501unsigned long post_time_ms(unsigned long base)
wdenkc08f1582003-04-27 22:52:51 +0000502{
Heiko Schocherd642b192011-09-14 19:34:33 +0000503#if defined(CONFIG_PPC) || defined(CONFIG_ARM)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000504 return (unsigned long)(get_ticks() / (get_tbclk() / CONFIG_SYS_HZ))
505 - base;
wdenkc08f1582003-04-27 22:52:51 +0000506#else
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100507#warning "Not implemented yet"
wdenkc08f1582003-04-27 22:52:51 +0000508 return 0; /* Not implemented yet */
509#endif
510}