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 Denk1a459662013-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-VILLARD52cb4d42009-05-16 12:14:54 +02009#include <stdio_dev.h>
wdenka042ac82002-09-12 22:36:57 +000010#include <watchdog.h>
Christian Rieschc90a4dd2011-12-09 16:54:02 +010011#include <div64.h>
wdenka042ac82002-09-12 22:36:57 +000012#include <post.h>
13
Mike Frysinger9146d132011-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 Denkd87080b2006-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 Schochere92372c2011-10-12 01:18:05 +000028int post_init_f(void)
wdenk4532cb62003-04-27 22:52:51 +000029{
wdenk4532cb62003-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 Denk50da8372011-10-29 09:42:22 +000036 if (test->init_f && test->init_f())
wdenk4532cb62003-04-27 22:52:51 +000037 res = -1;
wdenk4532cb62003-04-27 22:52:51 +000038 }
wdenk8bde7f72003-06-27 21:31:46 +000039
wdenk4532cb62003-04-27 22:52:51 +000040 gd->post_init_f_time = post_time_ms(0);
41 if (!gd->post_init_f_time)
Heiko Schochere92372c2011-10-12 01:18:05 +000042 printf("%s: post_time_ms not implemented\n", __FILE__);
wdenk4532cb62003-04-27 22:52:51 +000043
44 return res;
45}
46
Stefan Roese39ff7d52009-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 Frysinger9146d132011-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 Roese39ff7d52009-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 Schochere92372c2011-10-12 01:18:05 +000080void post_bootmode_init(void)
wdenka042ac82002-09-12 22:36:57 +000081{
Heiko Schochere92372c2011-10-12 01:18:05 +000082 int bootmode = post_bootmode_get(0);
wdenk27b207f2003-07-24 23:38:38 +000083 int newword;
wdenk42d1f032003-10-15 23:53:47 +000084
Heiko Schochere92372c2011-10-12 01:18:05 +000085 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST))
wdenk27b207f2003-07-24 23:38:38 +000086 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
Heiko Schochere92372c2011-10-12 01:18:05 +000087 else if (bootmode == 0)
wdenk27b207f2003-07-24 23:38:38 +000088 newword = BOOTMODE_MAGIC | POST_POWERON;
Heiko Schochere92372c2011-10-12 01:18:05 +000089 else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST)
wdenk27b207f2003-07-24 23:38:38 +000090 newword = BOOTMODE_MAGIC | POST_NORMAL;
Heiko Schochere92372c2011-10-12 01:18:05 +000091 else
wdenk27b207f2003-07-24 23:38:38 +000092 /* Use old value */
Wolfgang Denk50da8372011-10-29 09:42:22 +000093 newword = post_word_load() & ~POST_COLDBOOT;
wdenka042ac82002-09-12 22:36:57 +000094
wdenk27b207f2003-07-24 23:38:38 +000095 if (bootmode == 0)
wdenk27b207f2003-07-24 23:38:38 +000096 /* We are booting after power-on */
97 newword |= POST_COLDBOOT;
wdenk27b207f2003-07-24 23:38:38 +000098
Heiko Schochere92372c2011-10-12 01:18:05 +000099 post_word_store(newword);
wdenk27b207f2003-07-24 23:38:38 +0000100
wdenk228f29a2002-12-08 09:53:23 +0000101 /* Reset activity record */
102 gd->post_log_word = 0;
Valentin Longchamp79843952011-08-03 02:37:01 +0000103 gd->post_log_res = 0;
wdenka042ac82002-09-12 22:36:57 +0000104}
105
Heiko Schochere92372c2011-10-12 01:18:05 +0000106int post_bootmode_get(unsigned int *last_test)
wdenka042ac82002-09-12 22:36:57 +0000107{
Heiko Schochere92372c2011-10-12 01:18:05 +0000108 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000109 int bootmode;
110
Heiko Schochere92372c2011-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
wdenk27b207f2003-07-24 23:38:38 +0000114 bootmode = word & 0x7F;
wdenka042ac82002-09-12 22:36:57 +0000115
Heiko Schochere92372c2011-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
wdenk228f29a2002-12-08 09:53:23 +0000122/* POST tests run before relocation only mark status bits .... */
Heiko Schochere92372c2011-10-12 01:18:05 +0000123static void post_log_mark_start(unsigned long testid)
wdenk228f29a2002-12-08 09:53:23 +0000124{
Valentin Longchamp79843952011-08-03 02:37:01 +0000125 gd->post_log_word |= testid;
wdenk228f29a2002-12-08 09:53:23 +0000126}
127
Heiko Schochere92372c2011-10-12 01:18:05 +0000128static void post_log_mark_succ(unsigned long testid)
wdenk228f29a2002-12-08 09:53:23 +0000129{
Valentin Longchamp79843952011-08-03 02:37:01 +0000130 gd->post_log_res |= testid;
wdenk228f29a2002-12-08 09:53:23 +0000131}
132
133/* ... and the messages are output once we are relocated */
Heiko Schochere92372c2011-10-12 01:18:05 +0000134void post_output_backlog(void)
wdenk228f29a2002-12-08 09:53:23 +0000135{
wdenk228f29a2002-12-08 09:53:23 +0000136 int j;
137
138 for (j = 0; j < post_list_size; j++) {
Valentin Longchamp79843952011-08-03 02:37:01 +0000139 if (gd->post_log_word & (post_list[j].testid)) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000140 post_log("POST %s ", post_list[j].cmd);
Valentin Longchamp79843952011-08-03 02:37:01 +0000141 if (gd->post_log_res & post_list[j].testid)
Wolfgang Denk50da8372011-10-29 09:42:22 +0000142 post_log("PASSED\n");
wdenk63e73c92004-02-23 22:22:28 +0000143 else {
Heiko Schochere92372c2011-10-12 01:18:05 +0000144 post_log("FAILED\n");
Simon Glass770605e2012-02-13 13:51:18 +0000145 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
wdenk63e73c92004-02-23 22:22:28 +0000146 }
wdenk228f29a2002-12-08 09:53:23 +0000147 }
148 }
149}
150
Heiko Schochere92372c2011-10-12 01:18:05 +0000151static void post_bootmode_test_on(unsigned int last_test)
wdenka042ac82002-09-12 22:36:57 +0000152{
Heiko Schochere92372c2011-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 Schochere92372c2011-10-12 01:18:05 +0000159 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000160}
161
Heiko Schochere92372c2011-10-12 01:18:05 +0000162static void post_bootmode_test_off(void)
wdenka042ac82002-09-12 22:36:57 +0000163{
Heiko Schochere92372c2011-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 Schochere92372c2011-10-12 01:18:05 +0000168 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000169}
170
Valentin Longchamp212a0ca2011-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 Tikhonove262efe2008-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 Frysingerd2397812011-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 Denk50da8372011-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 Denk50da8372011-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 Denk50da8372011-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 Schochere92372c2011-10-12 01:18:05 +0000214 if (j == post_list_size)
Wolfgang Denk50da8372011-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 Longchamp212a0ca2011-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
wdenk6dff5522003-07-15 07:45:49 +0000233
Heiko Schochere92372c2011-10-12 01:18:05 +0000234 for (j = 0; j < post_list_size; j++)
235 if (test_flags[j] & POST_POWERON)
wdenk6dff5522003-07-15 07:45:49 +0000236 test_flags[j] |= POST_SLOWTEST;
wdenka042ac82002-09-12 22:36:57 +0000237}
238
Heiko Schochere92372c2011-10-12 01:18:05 +0000239void __show_post_progress(unsigned int test_num, int before, int result)
Michael Zaidmane070a562010-03-01 11:47:36 +0200240{
241}
Heiko Schochere92372c2011-10-12 01:18:05 +0000242void show_post_progress(unsigned int, int, int)
Michael Zaidmane070a562010-03-01 11:47:36 +0200243 __attribute__((weak, alias("__show_post_progress")));
244
Heiko Schochere92372c2011-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 Denk50da8372011-10-29 09:42:22 +0000250 WATCHDOG_RESET();
wdenka042ac82002-09-12 22:36:57 +0000251
252 if (!(flags & POST_REBOOT)) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000253 if ((test_flags & POST_REBOOT) &&
254 !(flags & POST_MANUAL)) {
255 post_bootmode_test_on(
Yuri Tikhonove262efe2008-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
wdenk228f29a2002-12-08 09:53:23 +0000260 if (test_flags & POST_PREREL)
Heiko Schochere92372c2011-10-12 01:18:05 +0000261 post_log_mark_start(test->testid);
wdenk228f29a2002-12-08 09:53:23 +0000262 else
Heiko Schochere92372c2011-10-12 01:18:05 +0000263 post_log("POST %s ", test->cmd);
wdenka042ac82002-09-12 22:36:57 +0000264 }
265
Michael Zaidmane070a562010-03-01 11:47:36 +0200266 show_post_progress(i, POST_BEFORE, POST_FAILED);
267
wdenk228f29a2002-12-08 09:53:23 +0000268 if (test_flags & POST_PREREL) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000269 if ((*test->test)(flags) == 0) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000270 post_log_mark_succ(test->testid);
Michael Zaidmane070a562010-03-01 11:47:36 +0200271 show_post_progress(i, POST_AFTER, POST_PASSED);
Wolfgang Denk50da8372011-10-29 09:42:22 +0000272 } else {
Michael Zaidmane070a562010-03-01 11:47:36 +0200273 show_post_progress(i, POST_AFTER, POST_FAILED);
Yuri Tikhonov28a38502008-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 }
wdenk228f29a2002-12-08 09:53:23 +0000279 } else {
James Kosin975afc32011-07-14 08:15:06 +0000280 if ((*test->test)(flags) != 0) {
281 post_log("FAILED\n");
Simon Glass770605e2012-02-13 13:51:18 +0000282 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
James Kosin975afc32011-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 }
wdenk228f29a2002-12-08 09:53:23 +0000292 }
wdenka042ac82002-09-12 22:36:57 +0000293
Wolfgang Denk50da8372011-10-29 09:42:22 +0000294 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL))
Heiko Schochere92372c2011-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 Denk50da8372011-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 Schochere92372c2011-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 Tikhonov28a38502008-05-08 15:45:26 +0200313 if (gd->flags & GD_FLG_POSTSTOP)
314 return 0;
315
Heiko Schochere92372c2011-10-12 01:18:05 +0000316 if (post_bootmode_get(&last) & POST_POWERTEST) {
Yuri Tikhonove262efe2008-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 Schochere92372c2011-10-12 01:18:05 +0000325 post_run_single(post_list + last,
wdenkea909b72002-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 Tikhonov28a38502008-05-08 15:45:26 +0200330 if (gd->flags & GD_FLG_POSTSTOP)
331 break;
Heiko Schochere92372c2011-10-12 01:18:05 +0000332 post_run_single(post_list + i,
wdenkea909b72002-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 Tikhonov28a38502008-05-08 15:45:26 +0200339 if (gd->flags & GD_FLG_POSTSTOP)
340 break;
Heiko Schochere92372c2011-10-12 01:18:05 +0000341 post_run_single(post_list + i,
wdenkea909b72002-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 Denk50da8372011-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 Laue5744ddc2008-05-30 09:48:14 +0200355 WATCHDOG_RESET();
Heiko Schochere92372c2011-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 Schochere92372c2011-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 Schochere92372c2011-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 Schochere92372c2011-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 Denk50da8372011-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 Schochere92372c2011-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 Denk50da8372011-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 Denk50da8372011-10-29 09:42:22 +0000395 if (i < post_list_size)
Heiko Schochere92372c2011-10-12 01:18:05 +0000396 return post_info_single(post_list + i, 1);
Wolfgang Denk50da8372011-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 Schochere92372c2011-10-12 01:18:05 +0000402int post_log(char *format, ...)
wdenka042ac82002-09-12 22:36:57 +0000403{
404 va_list args;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200405 char printbuffer[CONFIG_SYS_PBSIZE];
wdenka042ac82002-09-12 22:36:57 +0000406
Wolfgang Denk50da8372011-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 Denk4d6402b2011-10-29 09:42:23 +0000412 vsprintf(printbuffer, format, args);
Wolfgang Denk50da8372011-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
wdenk228f29a2002-12-08 09:53:23 +0000416 /* Send to the logbuffer */
Heiko Schochere92372c2011-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 Schochere92372c2011-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 Denk2e5167c2010-10-28 20:00:11 +0200426#ifdef CONFIG_NEEDS_MANUAL_RELOC
Heiko Schochere92372c2011-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 Denk50da8372011-10-29 09:42:22 +0000439 addr = (ulong)(test->name) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000440 test->name = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000441 }
442
443 if (test->cmd) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000444 addr = (ulong)(test->cmd) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000445 test->cmd = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000446 }
447
448 if (test->desc) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000449 addr = (ulong)(test->desc) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000450 test->desc = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000451 }
452
453 if (test->test) {
Wolfgang Denk50da8372011-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 }
wdenk4532cb62003-04-27 22:52:51 +0000457
458 if (test->init_f) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000459 addr = (ulong)(test->init_f) + gd->reloc_off;
wdenk4532cb62003-04-27 22:52:51 +0000460 test->init_f = (int (*)(void)) addr;
461 }
462
463 if (test->reloc) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000464 addr = (ulong)(test->reloc) + gd->reloc_off;
wdenk4532cb62003-04-27 22:52:51 +0000465 test->reloc = (void (*)(void)) addr;
wdenk8bde7f72003-06-27 21:31:46 +0000466
wdenk4532cb62003-04-27 22:52:51 +0000467 test->reloc();
468 }
wdenka042ac82002-09-12 22:36:57 +0000469 }
470}
Peter Tyser521af042009-09-21 11:20:36 -0500471#endif
wdenka042ac82002-09-12 22:36:57 +0000472
wdenk4532cb62003-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 Schochere92372c2011-10-12 01:18:05 +0000480unsigned long post_time_ms(unsigned long base)
wdenk4532cb62003-04-27 22:52:51 +0000481{
Valentin Longchamp4e518b82012-03-30 03:29:28 +0000482#if defined(CONFIG_PPC) || defined(CONFIG_BLACKFIN) || defined(CONFIG_ARM)
Christian Rieschc90a4dd2011-12-09 16:54:02 +0100483 return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ)
Heiko Schochere92372c2011-10-12 01:18:05 +0000484 - base;
wdenk4532cb62003-04-27 22:52:51 +0000485#else
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100486#warning "Not implemented yet"
wdenk4532cb62003-04-27 22:52:51 +0000487 return 0; /* Not implemented yet */
488#endif
489}