blob: 696a60f70a7146a021ba95c59b724b9fe3746c6e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
wdenka042ac82002-09-12 22:36:57 +00002/*
3 * (C) Copyright 2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
wdenka042ac82002-09-12 22:36:57 +00005 */
6
7#include <common.h>
Simon Glass3a7d5572019-08-01 09:46:42 -06008#include <env.h>
Simon Glass336d4612020-02-03 07:36:16 -07009#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020010#include <stdio_dev.h>
Simon Glass10453152019-11-14 12:57:30 -070011#include <time.h>
wdenka042ac82002-09-12 22:36:57 +000012#include <watchdog.h>
Christian Rieschc90a4dd2011-12-09 16:54:02 +010013#include <div64.h>
wdenka042ac82002-09-12 22:36:57 +000014#include <post.h>
15
Mike Frysinger9146d132011-05-10 07:01:21 +000016#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
17#include <asm/gpio.h>
18#endif
19
Wolfgang Denkd87080b2006-03-31 18:32:53 +020020DECLARE_GLOBAL_DATA_PTR;
21
wdenka042ac82002-09-12 22:36:57 +000022#define POST_MAX_NUMBER 32
23
24#define BOOTMODE_MAGIC 0xDEAD0000
25
Heiko Schochere92372c2011-10-12 01:18:05 +000026int post_init_f(void)
wdenk4532cb62003-04-27 22:52:51 +000027{
wdenk4532cb62003-04-27 22:52:51 +000028 int res = 0;
29 unsigned int i;
30
31 for (i = 0; i < post_list_size; i++) {
32 struct post_test *test = post_list + i;
33
Wolfgang Denk50da8372011-10-29 09:42:22 +000034 if (test->init_f && test->init_f())
wdenk4532cb62003-04-27 22:52:51 +000035 res = -1;
wdenk4532cb62003-04-27 22:52:51 +000036 }
wdenk8bde7f72003-06-27 21:31:46 +000037
wdenk4532cb62003-04-27 22:52:51 +000038 gd->post_init_f_time = post_time_ms(0);
39 if (!gd->post_init_f_time)
Heiko Schochere92372c2011-10-12 01:18:05 +000040 printf("%s: post_time_ms not implemented\n", __FILE__);
wdenk4532cb62003-04-27 22:52:51 +000041
42 return res;
43}
44
Stefan Roese39ff7d52009-12-03 06:24:30 +010045/*
46 * Supply a default implementation for post_hotkeys_pressed() for boards
47 * without hotkey support. We always return 0 here, so that the
48 * long-running tests won't be started.
49 *
50 * Boards with hotkey support can override this weak default function
51 * by defining one in their board specific code.
52 */
Jeroen Hofstee002ad7b2014-10-08 22:57:25 +020053__weak int post_hotkeys_pressed(void)
Stefan Roese39ff7d52009-12-03 06:24:30 +010054{
Mike Frysinger9146d132011-05-10 07:01:21 +000055#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
56 int ret;
57 unsigned gpio = CONFIG_SYS_POST_HOTKEYS_GPIO;
58
59 ret = gpio_request(gpio, "hotkeys");
60 if (ret) {
61 printf("POST: gpio hotkey request failed\n");
62 return 0;
63 }
64
65 gpio_direction_input(gpio);
66 ret = gpio_get_value(gpio);
67 gpio_free(gpio);
68
69 return ret;
70#endif
71
Stefan Roese39ff7d52009-12-03 06:24:30 +010072 return 0; /* No hotkeys supported */
73}
Stefan Roese39ff7d52009-12-03 06:24:30 +010074
Heiko Schochere92372c2011-10-12 01:18:05 +000075void post_bootmode_init(void)
wdenka042ac82002-09-12 22:36:57 +000076{
Heiko Schochere92372c2011-10-12 01:18:05 +000077 int bootmode = post_bootmode_get(0);
wdenk27b207f2003-07-24 23:38:38 +000078 int newword;
wdenk42d1f032003-10-15 23:53:47 +000079
Heiko Schochere92372c2011-10-12 01:18:05 +000080 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST))
wdenk27b207f2003-07-24 23:38:38 +000081 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
Heiko Schochere92372c2011-10-12 01:18:05 +000082 else if (bootmode == 0)
wdenk27b207f2003-07-24 23:38:38 +000083 newword = BOOTMODE_MAGIC | POST_POWERON;
Heiko Schochere92372c2011-10-12 01:18:05 +000084 else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST)
wdenk27b207f2003-07-24 23:38:38 +000085 newword = BOOTMODE_MAGIC | POST_NORMAL;
Heiko Schochere92372c2011-10-12 01:18:05 +000086 else
wdenk27b207f2003-07-24 23:38:38 +000087 /* Use old value */
Wolfgang Denk50da8372011-10-29 09:42:22 +000088 newword = post_word_load() & ~POST_COLDBOOT;
wdenka042ac82002-09-12 22:36:57 +000089
wdenk27b207f2003-07-24 23:38:38 +000090 if (bootmode == 0)
wdenk27b207f2003-07-24 23:38:38 +000091 /* We are booting after power-on */
92 newword |= POST_COLDBOOT;
wdenk27b207f2003-07-24 23:38:38 +000093
Heiko Schochere92372c2011-10-12 01:18:05 +000094 post_word_store(newword);
wdenk27b207f2003-07-24 23:38:38 +000095
wdenk228f29a2002-12-08 09:53:23 +000096 /* Reset activity record */
97 gd->post_log_word = 0;
Valentin Longchamp79843952011-08-03 02:37:01 +000098 gd->post_log_res = 0;
wdenka042ac82002-09-12 22:36:57 +000099}
100
Heiko Schochere92372c2011-10-12 01:18:05 +0000101int post_bootmode_get(unsigned int *last_test)
wdenka042ac82002-09-12 22:36:57 +0000102{
Heiko Schochere92372c2011-10-12 01:18:05 +0000103 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000104 int bootmode;
105
Heiko Schochere92372c2011-10-12 01:18:05 +0000106 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC)
wdenka042ac82002-09-12 22:36:57 +0000107 return 0;
wdenka042ac82002-09-12 22:36:57 +0000108
wdenk27b207f2003-07-24 23:38:38 +0000109 bootmode = word & 0x7F;
wdenka042ac82002-09-12 22:36:57 +0000110
Heiko Schochere92372c2011-10-12 01:18:05 +0000111 if (last_test && (bootmode & POST_POWERTEST))
wdenka042ac82002-09-12 22:36:57 +0000112 *last_test = (word >> 8) & 0xFF;
wdenka042ac82002-09-12 22:36:57 +0000113
114 return bootmode;
115}
116
wdenk228f29a2002-12-08 09:53:23 +0000117/* POST tests run before relocation only mark status bits .... */
Heiko Schochere92372c2011-10-12 01:18:05 +0000118static void post_log_mark_start(unsigned long testid)
wdenk228f29a2002-12-08 09:53:23 +0000119{
Valentin Longchamp79843952011-08-03 02:37:01 +0000120 gd->post_log_word |= testid;
wdenk228f29a2002-12-08 09:53:23 +0000121}
122
Heiko Schochere92372c2011-10-12 01:18:05 +0000123static void post_log_mark_succ(unsigned long testid)
wdenk228f29a2002-12-08 09:53:23 +0000124{
Valentin Longchamp79843952011-08-03 02:37:01 +0000125 gd->post_log_res |= testid;
wdenk228f29a2002-12-08 09:53:23 +0000126}
127
128/* ... and the messages are output once we are relocated */
Heiko Schochere92372c2011-10-12 01:18:05 +0000129void post_output_backlog(void)
wdenk228f29a2002-12-08 09:53:23 +0000130{
wdenk228f29a2002-12-08 09:53:23 +0000131 int j;
132
133 for (j = 0; j < post_list_size; j++) {
Valentin Longchamp79843952011-08-03 02:37:01 +0000134 if (gd->post_log_word & (post_list[j].testid)) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000135 post_log("POST %s ", post_list[j].cmd);
Valentin Longchamp79843952011-08-03 02:37:01 +0000136 if (gd->post_log_res & post_list[j].testid)
Wolfgang Denk50da8372011-10-29 09:42:22 +0000137 post_log("PASSED\n");
wdenk63e73c92004-02-23 22:22:28 +0000138 else {
Heiko Schochere92372c2011-10-12 01:18:05 +0000139 post_log("FAILED\n");
Simon Glass770605e2012-02-13 13:51:18 +0000140 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
wdenk63e73c92004-02-23 22:22:28 +0000141 }
wdenk228f29a2002-12-08 09:53:23 +0000142 }
143 }
144}
145
Heiko Schochere92372c2011-10-12 01:18:05 +0000146static void post_bootmode_test_on(unsigned int last_test)
wdenka042ac82002-09-12 22:36:57 +0000147{
Heiko Schochere92372c2011-10-12 01:18:05 +0000148 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000149
150 word |= POST_POWERTEST;
151
152 word |= (last_test & 0xFF) << 8;
153
Heiko Schochere92372c2011-10-12 01:18:05 +0000154 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000155}
156
Heiko Schochere92372c2011-10-12 01:18:05 +0000157static void post_bootmode_test_off(void)
wdenka042ac82002-09-12 22:36:57 +0000158{
Heiko Schochere92372c2011-10-12 01:18:05 +0000159 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000160
161 word &= ~POST_POWERTEST;
162
Heiko Schochere92372c2011-10-12 01:18:05 +0000163 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000164}
165
Valentin Longchamp212a0ca2011-08-03 02:37:02 +0000166#ifndef CONFIG_POST_SKIP_ENV_FLAGS
167static void post_get_env_flags(int *test_flags)
wdenka042ac82002-09-12 22:36:57 +0000168{
Yuri Tikhonove262efe2008-02-04 14:11:03 +0100169 int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST,
170 POST_CRITICAL };
171 char *var[] = { "post_poweron", "post_normal", "post_slowtest",
172 "post_critical" };
Mike Frysingerd2397812011-05-10 07:28:35 +0000173 int varnum = ARRAY_SIZE(var);
wdenka042ac82002-09-12 22:36:57 +0000174 char list[128]; /* long enough for POST list */
175 char *name;
176 char *s;
177 int last;
178 int i, j;
179
wdenka042ac82002-09-12 22:36:57 +0000180 for (i = 0; i < varnum; i++) {
Simon Glass00caae62017-08-03 12:22:12 -0600181 if (env_get_f(var[i], list, sizeof(list)) <= 0)
wdenka042ac82002-09-12 22:36:57 +0000182 continue;
183
Wolfgang Denk50da8372011-10-29 09:42:22 +0000184 for (j = 0; j < post_list_size; j++)
wdenka042ac82002-09-12 22:36:57 +0000185 test_flags[j] &= ~flag[i];
wdenka042ac82002-09-12 22:36:57 +0000186
187 last = 0;
188 name = list;
189 while (!last) {
190 while (*name && *name == ' ')
191 name++;
192 if (*name == 0)
193 break;
194 s = name + 1;
195 while (*s && *s != ' ')
196 s++;
197 if (*s == 0)
198 last = 1;
199 else
200 *s = 0;
201
202 for (j = 0; j < post_list_size; j++) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000203 if (strcmp(post_list[j].cmd, name) == 0) {
wdenka042ac82002-09-12 22:36:57 +0000204 test_flags[j] |= flag[i];
205 break;
206 }
207 }
208
Heiko Schochere92372c2011-10-12 01:18:05 +0000209 if (j == post_list_size)
Wolfgang Denk50da8372011-10-29 09:42:22 +0000210 printf("No such test: %s\n", name);
wdenka042ac82002-09-12 22:36:57 +0000211
212 name = s + 1;
213 }
214 }
Valentin Longchamp212a0ca2011-08-03 02:37:02 +0000215}
216#endif
217
218static void post_get_flags(int *test_flags)
219{
220 int j;
221
222 for (j = 0; j < post_list_size; j++)
223 test_flags[j] = post_list[j].flags;
224
225#ifndef CONFIG_POST_SKIP_ENV_FLAGS
226 post_get_env_flags(test_flags);
227#endif
wdenk6dff5522003-07-15 07:45:49 +0000228
Heiko Schochere92372c2011-10-12 01:18:05 +0000229 for (j = 0; j < post_list_size; j++)
230 if (test_flags[j] & POST_POWERON)
wdenk6dff5522003-07-15 07:45:49 +0000231 test_flags[j] |= POST_SLOWTEST;
wdenka042ac82002-09-12 22:36:57 +0000232}
233
Jeroen Hofstee002ad7b2014-10-08 22:57:25 +0200234__weak void show_post_progress(unsigned int test_num, int before, int result)
Michael Zaidmane070a562010-03-01 11:47:36 +0200235{
236}
Michael Zaidmane070a562010-03-01 11:47:36 +0200237
Heiko Schochere92372c2011-10-12 01:18:05 +0000238static int post_run_single(struct post_test *test,
wdenka042ac82002-09-12 22:36:57 +0000239 int test_flags, int flags, unsigned int i)
240{
241 if ((flags & test_flags & POST_ALWAYS) &&
242 (flags & test_flags & POST_MEM)) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000243 WATCHDOG_RESET();
wdenka042ac82002-09-12 22:36:57 +0000244
245 if (!(flags & POST_REBOOT)) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000246 if ((test_flags & POST_REBOOT) &&
247 !(flags & POST_MANUAL)) {
248 post_bootmode_test_on(
Yuri Tikhonove262efe2008-02-04 14:11:03 +0100249 (gd->flags & GD_FLG_POSTFAIL) ?
250 POST_FAIL_SAVE | i : i);
wdenka042ac82002-09-12 22:36:57 +0000251 }
252
wdenk228f29a2002-12-08 09:53:23 +0000253 if (test_flags & POST_PREREL)
Heiko Schochere92372c2011-10-12 01:18:05 +0000254 post_log_mark_start(test->testid);
wdenk228f29a2002-12-08 09:53:23 +0000255 else
Heiko Schochere92372c2011-10-12 01:18:05 +0000256 post_log("POST %s ", test->cmd);
wdenka042ac82002-09-12 22:36:57 +0000257 }
258
Michael Zaidmane070a562010-03-01 11:47:36 +0200259 show_post_progress(i, POST_BEFORE, POST_FAILED);
260
wdenk228f29a2002-12-08 09:53:23 +0000261 if (test_flags & POST_PREREL) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000262 if ((*test->test)(flags) == 0) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000263 post_log_mark_succ(test->testid);
Michael Zaidmane070a562010-03-01 11:47:36 +0200264 show_post_progress(i, POST_AFTER, POST_PASSED);
Wolfgang Denk50da8372011-10-29 09:42:22 +0000265 } else {
Michael Zaidmane070a562010-03-01 11:47:36 +0200266 show_post_progress(i, POST_AFTER, POST_FAILED);
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200267 if (test_flags & POST_CRITICAL)
268 gd->flags |= GD_FLG_POSTFAIL;
269 if (test_flags & POST_STOP)
270 gd->flags |= GD_FLG_POSTSTOP;
271 }
wdenk228f29a2002-12-08 09:53:23 +0000272 } else {
James Kosin975afc32011-07-14 08:15:06 +0000273 if ((*test->test)(flags) != 0) {
274 post_log("FAILED\n");
Simon Glass770605e2012-02-13 13:51:18 +0000275 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
James Kosin975afc32011-07-14 08:15:06 +0000276 show_post_progress(i, POST_AFTER, POST_FAILED);
277 if (test_flags & POST_CRITICAL)
278 gd->flags |= GD_FLG_POSTFAIL;
279 if (test_flags & POST_STOP)
280 gd->flags |= GD_FLG_POSTSTOP;
281 } else {
282 post_log("PASSED\n");
283 show_post_progress(i, POST_AFTER, POST_PASSED);
284 }
wdenk228f29a2002-12-08 09:53:23 +0000285 }
wdenka042ac82002-09-12 22:36:57 +0000286
Wolfgang Denk50da8372011-10-29 09:42:22 +0000287 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL))
Heiko Schochere92372c2011-10-12 01:18:05 +0000288 post_bootmode_test_off();
wdenka042ac82002-09-12 22:36:57 +0000289
290 return 0;
291 } else {
292 return -1;
293 }
294}
295
Wolfgang Denk50da8372011-10-29 09:42:22 +0000296int post_run(char *name, int flags)
wdenka042ac82002-09-12 22:36:57 +0000297{
298 unsigned int i;
299 int test_flags[POST_MAX_NUMBER];
300
Heiko Schochere92372c2011-10-12 01:18:05 +0000301 post_get_flags(test_flags);
wdenka042ac82002-09-12 22:36:57 +0000302
303 if (name == NULL) {
304 unsigned int last;
305
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200306 if (gd->flags & GD_FLG_POSTSTOP)
307 return 0;
308
Heiko Schochere92372c2011-10-12 01:18:05 +0000309 if (post_bootmode_get(&last) & POST_POWERTEST) {
Yuri Tikhonove262efe2008-02-04 14:11:03 +0100310 if (last & POST_FAIL_SAVE) {
311 last &= ~POST_FAIL_SAVE;
312 gd->flags |= GD_FLG_POSTFAIL;
313 }
wdenka042ac82002-09-12 22:36:57 +0000314 if (last < post_list_size &&
315 (flags & test_flags[last] & POST_ALWAYS) &&
316 (flags & test_flags[last] & POST_MEM)) {
317
Heiko Schochere92372c2011-10-12 01:18:05 +0000318 post_run_single(post_list + last,
wdenkea909b72002-11-21 23:11:29 +0000319 test_flags[last],
320 flags | POST_REBOOT, last);
wdenka042ac82002-09-12 22:36:57 +0000321
322 for (i = last + 1; i < post_list_size; i++) {
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200323 if (gd->flags & GD_FLG_POSTSTOP)
324 break;
Heiko Schochere92372c2011-10-12 01:18:05 +0000325 post_run_single(post_list + i,
wdenkea909b72002-11-21 23:11:29 +0000326 test_flags[i],
327 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000328 }
329 }
330 } else {
331 for (i = 0; i < post_list_size; i++) {
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200332 if (gd->flags & GD_FLG_POSTSTOP)
333 break;
Heiko Schochere92372c2011-10-12 01:18:05 +0000334 post_run_single(post_list + i,
wdenkea909b72002-11-21 23:11:29 +0000335 test_flags[i],
336 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000337 }
338 }
339
340 return 0;
341 } else {
342 for (i = 0; i < post_list_size; i++) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000343 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000344 break;
345 }
346
347 if (i < post_list_size) {
Sascha Laue5744ddc2008-05-30 09:48:14 +0200348 WATCHDOG_RESET();
Heiko Schochere92372c2011-10-12 01:18:05 +0000349 return post_run_single(post_list + i,
wdenka042ac82002-09-12 22:36:57 +0000350 test_flags[i],
351 flags, i);
352 } else {
353 return -1;
354 }
355 }
356}
357
Heiko Schochere92372c2011-10-12 01:18:05 +0000358static int post_info_single(struct post_test *test, int full)
wdenka042ac82002-09-12 22:36:57 +0000359{
360 if (test->flags & POST_MANUAL) {
361 if (full)
Heiko Schochere92372c2011-10-12 01:18:05 +0000362 printf("%s - %s\n"
wdenka042ac82002-09-12 22:36:57 +0000363 " %s\n", test->cmd, test->name, test->desc);
364 else
Heiko Schochere92372c2011-10-12 01:18:05 +0000365 printf(" %-15s - %s\n", test->cmd, test->name);
wdenka042ac82002-09-12 22:36:57 +0000366
367 return 0;
368 } else {
369 return -1;
370 }
371}
372
Wolfgang Denk50da8372011-10-29 09:42:22 +0000373int post_info(char *name)
wdenka042ac82002-09-12 22:36:57 +0000374{
375 unsigned int i;
376
377 if (name == NULL) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000378 for (i = 0; i < post_list_size; i++)
379 post_info_single(post_list + i, 0);
wdenka042ac82002-09-12 22:36:57 +0000380
381 return 0;
382 } else {
383 for (i = 0; i < post_list_size; i++) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000384 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000385 break;
386 }
387
Wolfgang Denk50da8372011-10-29 09:42:22 +0000388 if (i < post_list_size)
Heiko Schochere92372c2011-10-12 01:18:05 +0000389 return post_info_single(post_list + i, 1);
Wolfgang Denk50da8372011-10-29 09:42:22 +0000390 else
wdenka042ac82002-09-12 22:36:57 +0000391 return -1;
wdenka042ac82002-09-12 22:36:57 +0000392 }
393}
394
Heiko Schochere92372c2011-10-12 01:18:05 +0000395int post_log(char *format, ...)
wdenka042ac82002-09-12 22:36:57 +0000396{
397 va_list args;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200398 char printbuffer[CONFIG_SYS_PBSIZE];
wdenka042ac82002-09-12 22:36:57 +0000399
Wolfgang Denk50da8372011-10-29 09:42:22 +0000400 va_start(args, format);
wdenka042ac82002-09-12 22:36:57 +0000401
402 /* For this to work, printbuffer must be larger than
403 * anything we ever want to print.
404 */
Wolfgang Denk4d6402b2011-10-29 09:42:23 +0000405 vsprintf(printbuffer, format, args);
Wolfgang Denk50da8372011-10-29 09:42:22 +0000406 va_end(args);
wdenka042ac82002-09-12 22:36:57 +0000407
408 /* Send to the stdout file */
Heiko Schochere92372c2011-10-12 01:18:05 +0000409 puts(printbuffer);
wdenka042ac82002-09-12 22:36:57 +0000410
411 return 0;
412}
413
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200414#ifdef CONFIG_NEEDS_MANUAL_RELOC
Heiko Schochere92372c2011-10-12 01:18:05 +0000415void post_reloc(void)
wdenka042ac82002-09-12 22:36:57 +0000416{
wdenka042ac82002-09-12 22:36:57 +0000417 unsigned int i;
418
419 /*
420 * We have to relocate the test table manually
421 */
422 for (i = 0; i < post_list_size; i++) {
423 ulong addr;
424 struct post_test *test = post_list + i;
425
426 if (test->name) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000427 addr = (ulong)(test->name) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000428 test->name = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000429 }
430
431 if (test->cmd) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000432 addr = (ulong)(test->cmd) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000433 test->cmd = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000434 }
435
436 if (test->desc) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000437 addr = (ulong)(test->desc) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000438 test->desc = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000439 }
440
441 if (test->test) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000442 addr = (ulong)(test->test) + gd->reloc_off;
wdenka042ac82002-09-12 22:36:57 +0000443 test->test = (int (*)(int flags)) addr;
444 }
wdenk4532cb62003-04-27 22:52:51 +0000445
446 if (test->init_f) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000447 addr = (ulong)(test->init_f) + gd->reloc_off;
wdenk4532cb62003-04-27 22:52:51 +0000448 test->init_f = (int (*)(void)) addr;
449 }
450
451 if (test->reloc) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000452 addr = (ulong)(test->reloc) + gd->reloc_off;
wdenk4532cb62003-04-27 22:52:51 +0000453 test->reloc = (void (*)(void)) addr;
wdenk8bde7f72003-06-27 21:31:46 +0000454
wdenk4532cb62003-04-27 22:52:51 +0000455 test->reloc();
456 }
wdenka042ac82002-09-12 22:36:57 +0000457 }
458}
Peter Tyser521af042009-09-21 11:20:36 -0500459#endif
wdenka042ac82002-09-12 22:36:57 +0000460
wdenk4532cb62003-04-27 22:52:51 +0000461
462/*
463 * Some tests (e.g. SYSMON) need the time when post_init_f started,
464 * but we cannot use get_timer() at this point.
465 *
466 * On PowerPC we implement it using the timebase register.
467 */
Heiko Schochere92372c2011-10-12 01:18:05 +0000468unsigned long post_time_ms(unsigned long base)
wdenk4532cb62003-04-27 22:52:51 +0000469{
Tom Riniea3310e2017-03-14 11:08:10 -0400470#if defined(CONFIG_PPC) || defined(CONFIG_ARM)
Christian Rieschc90a4dd2011-12-09 16:54:02 +0100471 return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ)
Heiko Schochere92372c2011-10-12 01:18:05 +0000472 - base;
wdenk4532cb62003-04-27 22:52:51 +0000473#else
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100474#warning "Not implemented yet"
wdenk4532cb62003-04-27 22:52:51 +0000475 return 0; /* Not implemented yet */
476#endif
477}