blob: 4af5355fa5a20f9c2e763f37b269bea38d43e8ea [file] [log] [blame]
wdenka042ac82002-09-12 22:36:57 +00001/*
2 * (C) Copyright 2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenka042ac82002-09-12 22:36:57 +00006 */
7
8#include <common.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +02009#include <stdio_dev.h>
wdenka042ac82002-09-12 22:36:57 +000010#include <watchdog.h>
Christian Rieschbb968ec2011-12-09 16:54:02 +010011#include <div64.h>
wdenka042ac82002-09-12 22:36:57 +000012#include <post.h>
13
Mike Frysinger2073edd2011-05-10 07:01:21 +000014#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
15#include <asm/gpio.h>
16#endif
17
wdenk56f94be2002-11-05 16:35:14 +000018#ifdef CONFIG_LOGBUFFER
19#include <logbuff.h>
20#endif
21
Wolfgang Denk6405a152006-03-31 18:32:53 +020022DECLARE_GLOBAL_DATA_PTR;
23
wdenka042ac82002-09-12 22:36:57 +000024#define POST_MAX_NUMBER 32
25
26#define BOOTMODE_MAGIC 0xDEAD0000
27
Heiko Schocher51ee5912011-10-12 01:18:05 +000028int post_init_f(void)
wdenkc08f1582003-04-27 22:52:51 +000029{
wdenkc08f1582003-04-27 22:52:51 +000030 int res = 0;
31 unsigned int i;
32
33 for (i = 0; i < post_list_size; i++) {
34 struct post_test *test = post_list + i;
35
Wolfgang Denkf7a49f12011-10-29 09:42:22 +000036 if (test->init_f && test->init_f())
wdenkc08f1582003-04-27 22:52:51 +000037 res = -1;
wdenkc08f1582003-04-27 22:52:51 +000038 }
wdenk57b2d802003-06-27 21:31:46 +000039
wdenkc08f1582003-04-27 22:52:51 +000040 gd->post_init_f_time = post_time_ms(0);
41 if (!gd->post_init_f_time)
Heiko Schocher51ee5912011-10-12 01:18:05 +000042 printf("%s: post_time_ms not implemented\n", __FILE__);
wdenkc08f1582003-04-27 22:52:51 +000043
44 return res;
45}
46
Stefan Roesef0a15c52009-12-03 06:24:30 +010047/*
48 * Supply a default implementation for post_hotkeys_pressed() for boards
49 * without hotkey support. We always return 0 here, so that the
50 * long-running tests won't be started.
51 *
52 * Boards with hotkey support can override this weak default function
53 * by defining one in their board specific code.
54 */
55int __post_hotkeys_pressed(void)
56{
Mike Frysinger2073edd2011-05-10 07:01:21 +000057#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
58 int ret;
59 unsigned gpio = CONFIG_SYS_POST_HOTKEYS_GPIO;
60
61 ret = gpio_request(gpio, "hotkeys");
62 if (ret) {
63 printf("POST: gpio hotkey request failed\n");
64 return 0;
65 }
66
67 gpio_direction_input(gpio);
68 ret = gpio_get_value(gpio);
69 gpio_free(gpio);
70
71 return ret;
72#endif
73
Stefan Roesef0a15c52009-12-03 06:24:30 +010074 return 0; /* No hotkeys supported */
75}
76int post_hotkeys_pressed(void)
77 __attribute__((weak, alias("__post_hotkeys_pressed")));
78
79
Heiko Schocher51ee5912011-10-12 01:18:05 +000080void post_bootmode_init(void)
wdenka042ac82002-09-12 22:36:57 +000081{
Heiko Schocher51ee5912011-10-12 01:18:05 +000082 int bootmode = post_bootmode_get(0);
wdenk874ac262003-07-24 23:38:38 +000083 int newword;
wdenk9c53f402003-10-15 23:53:47 +000084
Heiko Schocher51ee5912011-10-12 01:18:05 +000085 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST))
wdenk874ac262003-07-24 23:38:38 +000086 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
Heiko Schocher51ee5912011-10-12 01:18:05 +000087 else if (bootmode == 0)
wdenk874ac262003-07-24 23:38:38 +000088 newword = BOOTMODE_MAGIC | POST_POWERON;
Heiko Schocher51ee5912011-10-12 01:18:05 +000089 else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST)
wdenk874ac262003-07-24 23:38:38 +000090 newword = BOOTMODE_MAGIC | POST_NORMAL;
Heiko Schocher51ee5912011-10-12 01:18:05 +000091 else
wdenk874ac262003-07-24 23:38:38 +000092 /* Use old value */
Wolfgang Denkf7a49f12011-10-29 09:42:22 +000093 newword = post_word_load() & ~POST_COLDBOOT;
wdenk874ac262003-07-24 23:38:38 +000094
95 if (bootmode == 0)
wdenk874ac262003-07-24 23:38:38 +000096 /* We are booting after power-on */
97 newword |= POST_COLDBOOT;
wdenka042ac82002-09-12 22:36:57 +000098
Heiko Schocher51ee5912011-10-12 01:18:05 +000099 post_word_store(newword);
wdenk874ac262003-07-24 23:38:38 +0000100
wdenk9dfa8d12002-12-08 09:53:23 +0000101 /* Reset activity record */
102 gd->post_log_word = 0;
Valentin Longchampb9181732011-08-03 02:37:01 +0000103 gd->post_log_res = 0;
wdenka042ac82002-09-12 22:36:57 +0000104}
105
Heiko Schocher51ee5912011-10-12 01:18:05 +0000106int post_bootmode_get(unsigned int *last_test)
wdenka042ac82002-09-12 22:36:57 +0000107{
Heiko Schocher51ee5912011-10-12 01:18:05 +0000108 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000109 int bootmode;
110
Heiko Schocher51ee5912011-10-12 01:18:05 +0000111 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC)
wdenka042ac82002-09-12 22:36:57 +0000112 return 0;
wdenka042ac82002-09-12 22:36:57 +0000113
wdenk874ac262003-07-24 23:38:38 +0000114 bootmode = word & 0x7F;
wdenka042ac82002-09-12 22:36:57 +0000115
Heiko Schocher51ee5912011-10-12 01:18:05 +0000116 if (last_test && (bootmode & POST_POWERTEST))
wdenka042ac82002-09-12 22:36:57 +0000117 *last_test = (word >> 8) & 0xFF;
wdenka042ac82002-09-12 22:36:57 +0000118
119 return bootmode;
120}
121
wdenk9dfa8d12002-12-08 09:53:23 +0000122/* POST tests run before relocation only mark status bits .... */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000123static void post_log_mark_start(unsigned long testid)
wdenk9dfa8d12002-12-08 09:53:23 +0000124{
Valentin Longchampb9181732011-08-03 02:37:01 +0000125 gd->post_log_word |= testid;
wdenk9dfa8d12002-12-08 09:53:23 +0000126}
127
Heiko Schocher51ee5912011-10-12 01:18:05 +0000128static void post_log_mark_succ(unsigned long testid)
wdenk9dfa8d12002-12-08 09:53:23 +0000129{
Valentin Longchampb9181732011-08-03 02:37:01 +0000130 gd->post_log_res |= testid;
wdenk9dfa8d12002-12-08 09:53:23 +0000131}
132
133/* ... and the messages are output once we are relocated */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000134void post_output_backlog(void)
wdenk9dfa8d12002-12-08 09:53:23 +0000135{
wdenk9dfa8d12002-12-08 09:53:23 +0000136 int j;
137
138 for (j = 0; j < post_list_size; j++) {
Valentin Longchampb9181732011-08-03 02:37:01 +0000139 if (gd->post_log_word & (post_list[j].testid)) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000140 post_log("POST %s ", post_list[j].cmd);
Valentin Longchampb9181732011-08-03 02:37:01 +0000141 if (gd->post_log_res & post_list[j].testid)
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000142 post_log("PASSED\n");
wdenke97d3d92004-02-23 22:22:28 +0000143 else {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000144 post_log("FAILED\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000145 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
wdenke97d3d92004-02-23 22:22:28 +0000146 }
wdenk9dfa8d12002-12-08 09:53:23 +0000147 }
148 }
149}
150
Heiko Schocher51ee5912011-10-12 01:18:05 +0000151static void post_bootmode_test_on(unsigned int last_test)
wdenka042ac82002-09-12 22:36:57 +0000152{
Heiko Schocher51ee5912011-10-12 01:18:05 +0000153 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000154
155 word |= POST_POWERTEST;
156
157 word |= (last_test & 0xFF) << 8;
158
Heiko Schocher51ee5912011-10-12 01:18:05 +0000159 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000160}
161
Heiko Schocher51ee5912011-10-12 01:18:05 +0000162static void post_bootmode_test_off(void)
wdenka042ac82002-09-12 22:36:57 +0000163{
Heiko Schocher51ee5912011-10-12 01:18:05 +0000164 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000165
166 word &= ~POST_POWERTEST;
167
Heiko Schocher51ee5912011-10-12 01:18:05 +0000168 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000169}
170
Valentin Longchampcfc88802011-08-03 02:37:02 +0000171#ifndef CONFIG_POST_SKIP_ENV_FLAGS
172static void post_get_env_flags(int *test_flags)
wdenka042ac82002-09-12 22:36:57 +0000173{
Yuri Tikhonov6a068a12008-02-04 14:11:03 +0100174 int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST,
175 POST_CRITICAL };
176 char *var[] = { "post_poweron", "post_normal", "post_slowtest",
177 "post_critical" };
Mike Frysinger83a687b2011-05-10 07:28:35 +0000178 int varnum = ARRAY_SIZE(var);
wdenka042ac82002-09-12 22:36:57 +0000179 char list[128]; /* long enough for POST list */
180 char *name;
181 char *s;
182 int last;
183 int i, j;
184
wdenka042ac82002-09-12 22:36:57 +0000185 for (i = 0; i < varnum; i++) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000186 if (getenv_f(var[i], list, sizeof(list)) <= 0)
wdenka042ac82002-09-12 22:36:57 +0000187 continue;
188
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000189 for (j = 0; j < post_list_size; j++)
wdenka042ac82002-09-12 22:36:57 +0000190 test_flags[j] &= ~flag[i];
wdenka042ac82002-09-12 22:36:57 +0000191
192 last = 0;
193 name = list;
194 while (!last) {
195 while (*name && *name == ' ')
196 name++;
197 if (*name == 0)
198 break;
199 s = name + 1;
200 while (*s && *s != ' ')
201 s++;
202 if (*s == 0)
203 last = 1;
204 else
205 *s = 0;
206
207 for (j = 0; j < post_list_size; j++) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000208 if (strcmp(post_list[j].cmd, name) == 0) {
wdenka042ac82002-09-12 22:36:57 +0000209 test_flags[j] |= flag[i];
210 break;
211 }
212 }
213
Heiko Schocher51ee5912011-10-12 01:18:05 +0000214 if (j == post_list_size)
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000215 printf("No such test: %s\n", name);
wdenka042ac82002-09-12 22:36:57 +0000216
217 name = s + 1;
218 }
219 }
Valentin Longchampcfc88802011-08-03 02:37:02 +0000220}
221#endif
222
223static void post_get_flags(int *test_flags)
224{
225 int j;
226
227 for (j = 0; j < post_list_size; j++)
228 test_flags[j] = post_list[j].flags;
229
230#ifndef CONFIG_POST_SKIP_ENV_FLAGS
231 post_get_env_flags(test_flags);
232#endif
wdenkca9bc762003-07-15 07:45:49 +0000233
Heiko Schocher51ee5912011-10-12 01:18:05 +0000234 for (j = 0; j < post_list_size; j++)
235 if (test_flags[j] & POST_POWERON)
wdenkca9bc762003-07-15 07:45:49 +0000236 test_flags[j] |= POST_SLOWTEST;
wdenka042ac82002-09-12 22:36:57 +0000237}
238
Heiko Schocher51ee5912011-10-12 01:18:05 +0000239void __show_post_progress(unsigned int test_num, int before, int result)
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200240{
241}
Heiko Schocher51ee5912011-10-12 01:18:05 +0000242void show_post_progress(unsigned int, int, int)
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200243 __attribute__((weak, alias("__show_post_progress")));
244
Heiko Schocher51ee5912011-10-12 01:18:05 +0000245static int post_run_single(struct post_test *test,
wdenka042ac82002-09-12 22:36:57 +0000246 int test_flags, int flags, unsigned int i)
247{
248 if ((flags & test_flags & POST_ALWAYS) &&
249 (flags & test_flags & POST_MEM)) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000250 WATCHDOG_RESET();
wdenka042ac82002-09-12 22:36:57 +0000251
252 if (!(flags & POST_REBOOT)) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000253 if ((test_flags & POST_REBOOT) &&
254 !(flags & POST_MANUAL)) {
255 post_bootmode_test_on(
Yuri Tikhonov6a068a12008-02-04 14:11:03 +0100256 (gd->flags & GD_FLG_POSTFAIL) ?
257 POST_FAIL_SAVE | i : i);
wdenka042ac82002-09-12 22:36:57 +0000258 }
259
wdenk9dfa8d12002-12-08 09:53:23 +0000260 if (test_flags & POST_PREREL)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000261 post_log_mark_start(test->testid);
wdenk9dfa8d12002-12-08 09:53:23 +0000262 else
Heiko Schocher51ee5912011-10-12 01:18:05 +0000263 post_log("POST %s ", test->cmd);
wdenka042ac82002-09-12 22:36:57 +0000264 }
265
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200266 show_post_progress(i, POST_BEFORE, POST_FAILED);
267
wdenk9dfa8d12002-12-08 09:53:23 +0000268 if (test_flags & POST_PREREL) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000269 if ((*test->test)(flags) == 0) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000270 post_log_mark_succ(test->testid);
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200271 show_post_progress(i, POST_AFTER, POST_PASSED);
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000272 } else {
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200273 show_post_progress(i, POST_AFTER, POST_FAILED);
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200274 if (test_flags & POST_CRITICAL)
275 gd->flags |= GD_FLG_POSTFAIL;
276 if (test_flags & POST_STOP)
277 gd->flags |= GD_FLG_POSTSTOP;
278 }
wdenk9dfa8d12002-12-08 09:53:23 +0000279 } else {
James Kosine7deffc2011-07-14 08:15:06 +0000280 if ((*test->test)(flags) != 0) {
281 post_log("FAILED\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000282 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
James Kosine7deffc2011-07-14 08:15:06 +0000283 show_post_progress(i, POST_AFTER, POST_FAILED);
284 if (test_flags & POST_CRITICAL)
285 gd->flags |= GD_FLG_POSTFAIL;
286 if (test_flags & POST_STOP)
287 gd->flags |= GD_FLG_POSTSTOP;
288 } else {
289 post_log("PASSED\n");
290 show_post_progress(i, POST_AFTER, POST_PASSED);
291 }
wdenk9dfa8d12002-12-08 09:53:23 +0000292 }
wdenka042ac82002-09-12 22:36:57 +0000293
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000294 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL))
Heiko Schocher51ee5912011-10-12 01:18:05 +0000295 post_bootmode_test_off();
wdenka042ac82002-09-12 22:36:57 +0000296
297 return 0;
298 } else {
299 return -1;
300 }
301}
302
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000303int post_run(char *name, int flags)
wdenka042ac82002-09-12 22:36:57 +0000304{
305 unsigned int i;
306 int test_flags[POST_MAX_NUMBER];
307
Heiko Schocher51ee5912011-10-12 01:18:05 +0000308 post_get_flags(test_flags);
wdenka042ac82002-09-12 22:36:57 +0000309
310 if (name == NULL) {
311 unsigned int last;
312
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200313 if (gd->flags & GD_FLG_POSTSTOP)
314 return 0;
315
Heiko Schocher51ee5912011-10-12 01:18:05 +0000316 if (post_bootmode_get(&last) & POST_POWERTEST) {
Yuri Tikhonov6a068a12008-02-04 14:11:03 +0100317 if (last & POST_FAIL_SAVE) {
318 last &= ~POST_FAIL_SAVE;
319 gd->flags |= GD_FLG_POSTFAIL;
320 }
wdenka042ac82002-09-12 22:36:57 +0000321 if (last < post_list_size &&
322 (flags & test_flags[last] & POST_ALWAYS) &&
323 (flags & test_flags[last] & POST_MEM)) {
324
Heiko Schocher51ee5912011-10-12 01:18:05 +0000325 post_run_single(post_list + last,
wdenk2029f4d2002-11-21 23:11:29 +0000326 test_flags[last],
327 flags | POST_REBOOT, last);
wdenka042ac82002-09-12 22:36:57 +0000328
329 for (i = last + 1; i < post_list_size; i++) {
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200330 if (gd->flags & GD_FLG_POSTSTOP)
331 break;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000332 post_run_single(post_list + i,
wdenk2029f4d2002-11-21 23:11:29 +0000333 test_flags[i],
334 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000335 }
336 }
337 } else {
338 for (i = 0; i < post_list_size; i++) {
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200339 if (gd->flags & GD_FLG_POSTSTOP)
340 break;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000341 post_run_single(post_list + i,
wdenk2029f4d2002-11-21 23:11:29 +0000342 test_flags[i],
343 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000344 }
345 }
346
347 return 0;
348 } else {
349 for (i = 0; i < post_list_size; i++) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000350 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000351 break;
352 }
353
354 if (i < post_list_size) {
Sascha Laue00150532008-05-30 09:48:14 +0200355 WATCHDOG_RESET();
Heiko Schocher51ee5912011-10-12 01:18:05 +0000356 return post_run_single(post_list + i,
wdenka042ac82002-09-12 22:36:57 +0000357 test_flags[i],
358 flags, i);
359 } else {
360 return -1;
361 }
362 }
363}
364
Heiko Schocher51ee5912011-10-12 01:18:05 +0000365static int post_info_single(struct post_test *test, int full)
wdenka042ac82002-09-12 22:36:57 +0000366{
367 if (test->flags & POST_MANUAL) {
368 if (full)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000369 printf("%s - %s\n"
wdenka042ac82002-09-12 22:36:57 +0000370 " %s\n", test->cmd, test->name, test->desc);
371 else
Heiko Schocher51ee5912011-10-12 01:18:05 +0000372 printf(" %-15s - %s\n", test->cmd, test->name);
wdenka042ac82002-09-12 22:36:57 +0000373
374 return 0;
375 } else {
376 return -1;
377 }
378}
379
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000380int post_info(char *name)
wdenka042ac82002-09-12 22:36:57 +0000381{
382 unsigned int i;
383
384 if (name == NULL) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000385 for (i = 0; i < post_list_size; i++)
386 post_info_single(post_list + i, 0);
wdenka042ac82002-09-12 22:36:57 +0000387
388 return 0;
389 } else {
390 for (i = 0; i < post_list_size; i++) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000391 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000392 break;
393 }
394
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000395 if (i < post_list_size)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000396 return post_info_single(post_list + i, 1);
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000397 else
wdenka042ac82002-09-12 22:36:57 +0000398 return -1;
wdenka042ac82002-09-12 22:36:57 +0000399 }
400}
401
Heiko Schocher51ee5912011-10-12 01:18:05 +0000402int post_log(char *format, ...)
wdenka042ac82002-09-12 22:36:57 +0000403{
404 va_list args;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200405 char printbuffer[CONFIG_SYS_PBSIZE];
wdenka042ac82002-09-12 22:36:57 +0000406
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000407 va_start(args, format);
wdenka042ac82002-09-12 22:36:57 +0000408
409 /* For this to work, printbuffer must be larger than
410 * anything we ever want to print.
411 */
Wolfgang Denkbedfa0a2011-10-29 09:42:23 +0000412 vsprintf(printbuffer, format, args);
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000413 va_end(args);
wdenka042ac82002-09-12 22:36:57 +0000414
wdenk56f94be2002-11-05 16:35:14 +0000415#ifdef CONFIG_LOGBUFFER
wdenk9dfa8d12002-12-08 09:53:23 +0000416 /* Send to the logbuffer */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000417 logbuff_log(printbuffer);
wdenk56f94be2002-11-05 16:35:14 +0000418#else
wdenka042ac82002-09-12 22:36:57 +0000419 /* Send to the stdout file */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000420 puts(printbuffer);
wdenk56f94be2002-11-05 16:35:14 +0000421#endif
wdenka042ac82002-09-12 22:36:57 +0000422
423 return 0;
424}
425
Wolfgang Denkd0813e52010-10-28 20:00:11 +0200426#ifdef CONFIG_NEEDS_MANUAL_RELOC
Heiko Schocher51ee5912011-10-12 01:18:05 +0000427void post_reloc(void)
wdenka042ac82002-09-12 22:36:57 +0000428{
wdenka042ac82002-09-12 22:36:57 +0000429 unsigned int i;
430
431 /*
432 * We have to relocate the test table manually
433 */
434 for (i = 0; i < post_list_size; i++) {
435 ulong addr;
436 struct post_test *test = post_list + i;
437
438 if (test->name) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000439 addr = (ulong)(test->name) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000440 test->name = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000441 }
442
443 if (test->cmd) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000444 addr = (ulong)(test->cmd) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000445 test->cmd = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000446 }
447
448 if (test->desc) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000449 addr = (ulong)(test->desc) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000450 test->desc = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000451 }
452
453 if (test->test) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000454 addr = (ulong)(test->test) + gd->reloc_off;
wdenka042ac82002-09-12 22:36:57 +0000455 test->test = (int (*)(int flags)) addr;
456 }
wdenkc08f1582003-04-27 22:52:51 +0000457
458 if (test->init_f) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000459 addr = (ulong)(test->init_f) + gd->reloc_off;
wdenkc08f1582003-04-27 22:52:51 +0000460 test->init_f = (int (*)(void)) addr;
461 }
462
463 if (test->reloc) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000464 addr = (ulong)(test->reloc) + gd->reloc_off;
wdenkc08f1582003-04-27 22:52:51 +0000465 test->reloc = (void (*)(void)) addr;
wdenk57b2d802003-06-27 21:31:46 +0000466
wdenkc08f1582003-04-27 22:52:51 +0000467 test->reloc();
468 }
wdenka042ac82002-09-12 22:36:57 +0000469 }
470}
Peter Tyser9057cbf2009-09-21 11:20:36 -0500471#endif
wdenka042ac82002-09-12 22:36:57 +0000472
wdenkc08f1582003-04-27 22:52:51 +0000473
474/*
475 * Some tests (e.g. SYSMON) need the time when post_init_f started,
476 * but we cannot use get_timer() at this point.
477 *
478 * On PowerPC we implement it using the timebase register.
479 */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000480unsigned long post_time_ms(unsigned long base)
wdenkc08f1582003-04-27 22:52:51 +0000481{
Valentin Longchampb2184f22012-03-30 03:29:28 +0000482#if defined(CONFIG_PPC) || defined(CONFIG_BLACKFIN) || defined(CONFIG_ARM)
Christian Rieschbb968ec2011-12-09 16:54:02 +0100483 return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000484 - base;
wdenkc08f1582003-04-27 22:52:51 +0000485#else
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100486#warning "Not implemented yet"
wdenkc08f1582003-04-27 22:52:51 +0000487 return 0; /* Not implemented yet */
488#endif
489}