blob: f27138ddaaf3bba4fa165e20c13de945cbbd85d4 [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>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +02009#include <stdio_dev.h>
Simon Glass10453152019-11-14 12:57:30 -070010#include <time.h>
wdenka042ac82002-09-12 22:36:57 +000011#include <watchdog.h>
Christian Rieschc90a4dd2011-12-09 16:54:02 +010012#include <div64.h>
wdenka042ac82002-09-12 22:36:57 +000013#include <post.h>
14
Mike Frysinger9146d132011-05-10 07:01:21 +000015#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
16#include <asm/gpio.h>
17#endif
18
Wolfgang Denkd87080b2006-03-31 18:32:53 +020019DECLARE_GLOBAL_DATA_PTR;
20
wdenka042ac82002-09-12 22:36:57 +000021#define POST_MAX_NUMBER 32
22
23#define BOOTMODE_MAGIC 0xDEAD0000
24
Heiko Schochere92372c2011-10-12 01:18:05 +000025int post_init_f(void)
wdenk4532cb62003-04-27 22:52:51 +000026{
wdenk4532cb62003-04-27 22:52:51 +000027 int res = 0;
28 unsigned int i;
29
30 for (i = 0; i < post_list_size; i++) {
31 struct post_test *test = post_list + i;
32
Wolfgang Denk50da8372011-10-29 09:42:22 +000033 if (test->init_f && test->init_f())
wdenk4532cb62003-04-27 22:52:51 +000034 res = -1;
wdenk4532cb62003-04-27 22:52:51 +000035 }
wdenk8bde7f72003-06-27 21:31:46 +000036
wdenk4532cb62003-04-27 22:52:51 +000037 gd->post_init_f_time = post_time_ms(0);
38 if (!gd->post_init_f_time)
Heiko Schochere92372c2011-10-12 01:18:05 +000039 printf("%s: post_time_ms not implemented\n", __FILE__);
wdenk4532cb62003-04-27 22:52:51 +000040
41 return res;
42}
43
Stefan Roese39ff7d52009-12-03 06:24:30 +010044/*
45 * Supply a default implementation for post_hotkeys_pressed() for boards
46 * without hotkey support. We always return 0 here, so that the
47 * long-running tests won't be started.
48 *
49 * Boards with hotkey support can override this weak default function
50 * by defining one in their board specific code.
51 */
Jeroen Hofstee002ad7b2014-10-08 22:57:25 +020052__weak int post_hotkeys_pressed(void)
Stefan Roese39ff7d52009-12-03 06:24:30 +010053{
Mike Frysinger9146d132011-05-10 07:01:21 +000054#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
55 int ret;
56 unsigned gpio = CONFIG_SYS_POST_HOTKEYS_GPIO;
57
58 ret = gpio_request(gpio, "hotkeys");
59 if (ret) {
60 printf("POST: gpio hotkey request failed\n");
61 return 0;
62 }
63
64 gpio_direction_input(gpio);
65 ret = gpio_get_value(gpio);
66 gpio_free(gpio);
67
68 return ret;
69#endif
70
Stefan Roese39ff7d52009-12-03 06:24:30 +010071 return 0; /* No hotkeys supported */
72}
Stefan Roese39ff7d52009-12-03 06:24:30 +010073
Heiko Schochere92372c2011-10-12 01:18:05 +000074void post_bootmode_init(void)
wdenka042ac82002-09-12 22:36:57 +000075{
Heiko Schochere92372c2011-10-12 01:18:05 +000076 int bootmode = post_bootmode_get(0);
wdenk27b207f2003-07-24 23:38:38 +000077 int newword;
wdenk42d1f032003-10-15 23:53:47 +000078
Heiko Schochere92372c2011-10-12 01:18:05 +000079 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST))
wdenk27b207f2003-07-24 23:38:38 +000080 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
Heiko Schochere92372c2011-10-12 01:18:05 +000081 else if (bootmode == 0)
wdenk27b207f2003-07-24 23:38:38 +000082 newword = BOOTMODE_MAGIC | POST_POWERON;
Heiko Schochere92372c2011-10-12 01:18:05 +000083 else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST)
wdenk27b207f2003-07-24 23:38:38 +000084 newword = BOOTMODE_MAGIC | POST_NORMAL;
Heiko Schochere92372c2011-10-12 01:18:05 +000085 else
wdenk27b207f2003-07-24 23:38:38 +000086 /* Use old value */
Wolfgang Denk50da8372011-10-29 09:42:22 +000087 newword = post_word_load() & ~POST_COLDBOOT;
wdenka042ac82002-09-12 22:36:57 +000088
wdenk27b207f2003-07-24 23:38:38 +000089 if (bootmode == 0)
wdenk27b207f2003-07-24 23:38:38 +000090 /* We are booting after power-on */
91 newword |= POST_COLDBOOT;
wdenk27b207f2003-07-24 23:38:38 +000092
Heiko Schochere92372c2011-10-12 01:18:05 +000093 post_word_store(newword);
wdenk27b207f2003-07-24 23:38:38 +000094
wdenk228f29a2002-12-08 09:53:23 +000095 /* Reset activity record */
96 gd->post_log_word = 0;
Valentin Longchamp79843952011-08-03 02:37:01 +000097 gd->post_log_res = 0;
wdenka042ac82002-09-12 22:36:57 +000098}
99
Heiko Schochere92372c2011-10-12 01:18:05 +0000100int post_bootmode_get(unsigned int *last_test)
wdenka042ac82002-09-12 22:36:57 +0000101{
Heiko Schochere92372c2011-10-12 01:18:05 +0000102 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000103 int bootmode;
104
Heiko Schochere92372c2011-10-12 01:18:05 +0000105 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC)
wdenka042ac82002-09-12 22:36:57 +0000106 return 0;
wdenka042ac82002-09-12 22:36:57 +0000107
wdenk27b207f2003-07-24 23:38:38 +0000108 bootmode = word & 0x7F;
wdenka042ac82002-09-12 22:36:57 +0000109
Heiko Schochere92372c2011-10-12 01:18:05 +0000110 if (last_test && (bootmode & POST_POWERTEST))
wdenka042ac82002-09-12 22:36:57 +0000111 *last_test = (word >> 8) & 0xFF;
wdenka042ac82002-09-12 22:36:57 +0000112
113 return bootmode;
114}
115
wdenk228f29a2002-12-08 09:53:23 +0000116/* POST tests run before relocation only mark status bits .... */
Heiko Schochere92372c2011-10-12 01:18:05 +0000117static void post_log_mark_start(unsigned long testid)
wdenk228f29a2002-12-08 09:53:23 +0000118{
Valentin Longchamp79843952011-08-03 02:37:01 +0000119 gd->post_log_word |= testid;
wdenk228f29a2002-12-08 09:53:23 +0000120}
121
Heiko Schochere92372c2011-10-12 01:18:05 +0000122static void post_log_mark_succ(unsigned long testid)
wdenk228f29a2002-12-08 09:53:23 +0000123{
Valentin Longchamp79843952011-08-03 02:37:01 +0000124 gd->post_log_res |= testid;
wdenk228f29a2002-12-08 09:53:23 +0000125}
126
127/* ... and the messages are output once we are relocated */
Heiko Schochere92372c2011-10-12 01:18:05 +0000128void post_output_backlog(void)
wdenk228f29a2002-12-08 09:53:23 +0000129{
wdenk228f29a2002-12-08 09:53:23 +0000130 int j;
131
132 for (j = 0; j < post_list_size; j++) {
Valentin Longchamp79843952011-08-03 02:37:01 +0000133 if (gd->post_log_word & (post_list[j].testid)) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000134 post_log("POST %s ", post_list[j].cmd);
Valentin Longchamp79843952011-08-03 02:37:01 +0000135 if (gd->post_log_res & post_list[j].testid)
Wolfgang Denk50da8372011-10-29 09:42:22 +0000136 post_log("PASSED\n");
wdenk63e73c92004-02-23 22:22:28 +0000137 else {
Heiko Schochere92372c2011-10-12 01:18:05 +0000138 post_log("FAILED\n");
Simon Glass770605e2012-02-13 13:51:18 +0000139 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
wdenk63e73c92004-02-23 22:22:28 +0000140 }
wdenk228f29a2002-12-08 09:53:23 +0000141 }
142 }
143}
144
Heiko Schochere92372c2011-10-12 01:18:05 +0000145static void post_bootmode_test_on(unsigned int last_test)
wdenka042ac82002-09-12 22:36:57 +0000146{
Heiko Schochere92372c2011-10-12 01:18:05 +0000147 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000148
149 word |= POST_POWERTEST;
150
151 word |= (last_test & 0xFF) << 8;
152
Heiko Schochere92372c2011-10-12 01:18:05 +0000153 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000154}
155
Heiko Schochere92372c2011-10-12 01:18:05 +0000156static void post_bootmode_test_off(void)
wdenka042ac82002-09-12 22:36:57 +0000157{
Heiko Schochere92372c2011-10-12 01:18:05 +0000158 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000159
160 word &= ~POST_POWERTEST;
161
Heiko Schochere92372c2011-10-12 01:18:05 +0000162 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000163}
164
Valentin Longchamp212a0ca2011-08-03 02:37:02 +0000165#ifndef CONFIG_POST_SKIP_ENV_FLAGS
166static void post_get_env_flags(int *test_flags)
wdenka042ac82002-09-12 22:36:57 +0000167{
Yuri Tikhonove262efe2008-02-04 14:11:03 +0100168 int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST,
169 POST_CRITICAL };
170 char *var[] = { "post_poweron", "post_normal", "post_slowtest",
171 "post_critical" };
Mike Frysingerd2397812011-05-10 07:28:35 +0000172 int varnum = ARRAY_SIZE(var);
wdenka042ac82002-09-12 22:36:57 +0000173 char list[128]; /* long enough for POST list */
174 char *name;
175 char *s;
176 int last;
177 int i, j;
178
wdenka042ac82002-09-12 22:36:57 +0000179 for (i = 0; i < varnum; i++) {
Simon Glass00caae62017-08-03 12:22:12 -0600180 if (env_get_f(var[i], list, sizeof(list)) <= 0)
wdenka042ac82002-09-12 22:36:57 +0000181 continue;
182
Wolfgang Denk50da8372011-10-29 09:42:22 +0000183 for (j = 0; j < post_list_size; j++)
wdenka042ac82002-09-12 22:36:57 +0000184 test_flags[j] &= ~flag[i];
wdenka042ac82002-09-12 22:36:57 +0000185
186 last = 0;
187 name = list;
188 while (!last) {
189 while (*name && *name == ' ')
190 name++;
191 if (*name == 0)
192 break;
193 s = name + 1;
194 while (*s && *s != ' ')
195 s++;
196 if (*s == 0)
197 last = 1;
198 else
199 *s = 0;
200
201 for (j = 0; j < post_list_size; j++) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000202 if (strcmp(post_list[j].cmd, name) == 0) {
wdenka042ac82002-09-12 22:36:57 +0000203 test_flags[j] |= flag[i];
204 break;
205 }
206 }
207
Heiko Schochere92372c2011-10-12 01:18:05 +0000208 if (j == post_list_size)
Wolfgang Denk50da8372011-10-29 09:42:22 +0000209 printf("No such test: %s\n", name);
wdenka042ac82002-09-12 22:36:57 +0000210
211 name = s + 1;
212 }
213 }
Valentin Longchamp212a0ca2011-08-03 02:37:02 +0000214}
215#endif
216
217static void post_get_flags(int *test_flags)
218{
219 int j;
220
221 for (j = 0; j < post_list_size; j++)
222 test_flags[j] = post_list[j].flags;
223
224#ifndef CONFIG_POST_SKIP_ENV_FLAGS
225 post_get_env_flags(test_flags);
226#endif
wdenk6dff5522003-07-15 07:45:49 +0000227
Heiko Schochere92372c2011-10-12 01:18:05 +0000228 for (j = 0; j < post_list_size; j++)
229 if (test_flags[j] & POST_POWERON)
wdenk6dff5522003-07-15 07:45:49 +0000230 test_flags[j] |= POST_SLOWTEST;
wdenka042ac82002-09-12 22:36:57 +0000231}
232
Jeroen Hofstee002ad7b2014-10-08 22:57:25 +0200233__weak void show_post_progress(unsigned int test_num, int before, int result)
Michael Zaidmane070a562010-03-01 11:47:36 +0200234{
235}
Michael Zaidmane070a562010-03-01 11:47:36 +0200236
Heiko Schochere92372c2011-10-12 01:18:05 +0000237static int post_run_single(struct post_test *test,
wdenka042ac82002-09-12 22:36:57 +0000238 int test_flags, int flags, unsigned int i)
239{
240 if ((flags & test_flags & POST_ALWAYS) &&
241 (flags & test_flags & POST_MEM)) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000242 WATCHDOG_RESET();
wdenka042ac82002-09-12 22:36:57 +0000243
244 if (!(flags & POST_REBOOT)) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000245 if ((test_flags & POST_REBOOT) &&
246 !(flags & POST_MANUAL)) {
247 post_bootmode_test_on(
Yuri Tikhonove262efe2008-02-04 14:11:03 +0100248 (gd->flags & GD_FLG_POSTFAIL) ?
249 POST_FAIL_SAVE | i : i);
wdenka042ac82002-09-12 22:36:57 +0000250 }
251
wdenk228f29a2002-12-08 09:53:23 +0000252 if (test_flags & POST_PREREL)
Heiko Schochere92372c2011-10-12 01:18:05 +0000253 post_log_mark_start(test->testid);
wdenk228f29a2002-12-08 09:53:23 +0000254 else
Heiko Schochere92372c2011-10-12 01:18:05 +0000255 post_log("POST %s ", test->cmd);
wdenka042ac82002-09-12 22:36:57 +0000256 }
257
Michael Zaidmane070a562010-03-01 11:47:36 +0200258 show_post_progress(i, POST_BEFORE, POST_FAILED);
259
wdenk228f29a2002-12-08 09:53:23 +0000260 if (test_flags & POST_PREREL) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000261 if ((*test->test)(flags) == 0) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000262 post_log_mark_succ(test->testid);
Michael Zaidmane070a562010-03-01 11:47:36 +0200263 show_post_progress(i, POST_AFTER, POST_PASSED);
Wolfgang Denk50da8372011-10-29 09:42:22 +0000264 } else {
Michael Zaidmane070a562010-03-01 11:47:36 +0200265 show_post_progress(i, POST_AFTER, POST_FAILED);
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200266 if (test_flags & POST_CRITICAL)
267 gd->flags |= GD_FLG_POSTFAIL;
268 if (test_flags & POST_STOP)
269 gd->flags |= GD_FLG_POSTSTOP;
270 }
wdenk228f29a2002-12-08 09:53:23 +0000271 } else {
James Kosin975afc32011-07-14 08:15:06 +0000272 if ((*test->test)(flags) != 0) {
273 post_log("FAILED\n");
Simon Glass770605e2012-02-13 13:51:18 +0000274 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
James Kosin975afc32011-07-14 08:15:06 +0000275 show_post_progress(i, POST_AFTER, POST_FAILED);
276 if (test_flags & POST_CRITICAL)
277 gd->flags |= GD_FLG_POSTFAIL;
278 if (test_flags & POST_STOP)
279 gd->flags |= GD_FLG_POSTSTOP;
280 } else {
281 post_log("PASSED\n");
282 show_post_progress(i, POST_AFTER, POST_PASSED);
283 }
wdenk228f29a2002-12-08 09:53:23 +0000284 }
wdenka042ac82002-09-12 22:36:57 +0000285
Wolfgang Denk50da8372011-10-29 09:42:22 +0000286 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL))
Heiko Schochere92372c2011-10-12 01:18:05 +0000287 post_bootmode_test_off();
wdenka042ac82002-09-12 22:36:57 +0000288
289 return 0;
290 } else {
291 return -1;
292 }
293}
294
Wolfgang Denk50da8372011-10-29 09:42:22 +0000295int post_run(char *name, int flags)
wdenka042ac82002-09-12 22:36:57 +0000296{
297 unsigned int i;
298 int test_flags[POST_MAX_NUMBER];
299
Heiko Schochere92372c2011-10-12 01:18:05 +0000300 post_get_flags(test_flags);
wdenka042ac82002-09-12 22:36:57 +0000301
302 if (name == NULL) {
303 unsigned int last;
304
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200305 if (gd->flags & GD_FLG_POSTSTOP)
306 return 0;
307
Heiko Schochere92372c2011-10-12 01:18:05 +0000308 if (post_bootmode_get(&last) & POST_POWERTEST) {
Yuri Tikhonove262efe2008-02-04 14:11:03 +0100309 if (last & POST_FAIL_SAVE) {
310 last &= ~POST_FAIL_SAVE;
311 gd->flags |= GD_FLG_POSTFAIL;
312 }
wdenka042ac82002-09-12 22:36:57 +0000313 if (last < post_list_size &&
314 (flags & test_flags[last] & POST_ALWAYS) &&
315 (flags & test_flags[last] & POST_MEM)) {
316
Heiko Schochere92372c2011-10-12 01:18:05 +0000317 post_run_single(post_list + last,
wdenkea909b72002-11-21 23:11:29 +0000318 test_flags[last],
319 flags | POST_REBOOT, last);
wdenka042ac82002-09-12 22:36:57 +0000320
321 for (i = last + 1; i < post_list_size; i++) {
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200322 if (gd->flags & GD_FLG_POSTSTOP)
323 break;
Heiko Schochere92372c2011-10-12 01:18:05 +0000324 post_run_single(post_list + i,
wdenkea909b72002-11-21 23:11:29 +0000325 test_flags[i],
326 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000327 }
328 }
329 } else {
330 for (i = 0; i < post_list_size; i++) {
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200331 if (gd->flags & GD_FLG_POSTSTOP)
332 break;
Heiko Schochere92372c2011-10-12 01:18:05 +0000333 post_run_single(post_list + i,
wdenkea909b72002-11-21 23:11:29 +0000334 test_flags[i],
335 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000336 }
337 }
338
339 return 0;
340 } else {
341 for (i = 0; i < post_list_size; i++) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000342 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000343 break;
344 }
345
346 if (i < post_list_size) {
Sascha Laue5744ddc2008-05-30 09:48:14 +0200347 WATCHDOG_RESET();
Heiko Schochere92372c2011-10-12 01:18:05 +0000348 return post_run_single(post_list + i,
wdenka042ac82002-09-12 22:36:57 +0000349 test_flags[i],
350 flags, i);
351 } else {
352 return -1;
353 }
354 }
355}
356
Heiko Schochere92372c2011-10-12 01:18:05 +0000357static int post_info_single(struct post_test *test, int full)
wdenka042ac82002-09-12 22:36:57 +0000358{
359 if (test->flags & POST_MANUAL) {
360 if (full)
Heiko Schochere92372c2011-10-12 01:18:05 +0000361 printf("%s - %s\n"
wdenka042ac82002-09-12 22:36:57 +0000362 " %s\n", test->cmd, test->name, test->desc);
363 else
Heiko Schochere92372c2011-10-12 01:18:05 +0000364 printf(" %-15s - %s\n", test->cmd, test->name);
wdenka042ac82002-09-12 22:36:57 +0000365
366 return 0;
367 } else {
368 return -1;
369 }
370}
371
Wolfgang Denk50da8372011-10-29 09:42:22 +0000372int post_info(char *name)
wdenka042ac82002-09-12 22:36:57 +0000373{
374 unsigned int i;
375
376 if (name == NULL) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000377 for (i = 0; i < post_list_size; i++)
378 post_info_single(post_list + i, 0);
wdenka042ac82002-09-12 22:36:57 +0000379
380 return 0;
381 } else {
382 for (i = 0; i < post_list_size; i++) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000383 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000384 break;
385 }
386
Wolfgang Denk50da8372011-10-29 09:42:22 +0000387 if (i < post_list_size)
Heiko Schochere92372c2011-10-12 01:18:05 +0000388 return post_info_single(post_list + i, 1);
Wolfgang Denk50da8372011-10-29 09:42:22 +0000389 else
wdenka042ac82002-09-12 22:36:57 +0000390 return -1;
wdenka042ac82002-09-12 22:36:57 +0000391 }
392}
393
Heiko Schochere92372c2011-10-12 01:18:05 +0000394int post_log(char *format, ...)
wdenka042ac82002-09-12 22:36:57 +0000395{
396 va_list args;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200397 char printbuffer[CONFIG_SYS_PBSIZE];
wdenka042ac82002-09-12 22:36:57 +0000398
Wolfgang Denk50da8372011-10-29 09:42:22 +0000399 va_start(args, format);
wdenka042ac82002-09-12 22:36:57 +0000400
401 /* For this to work, printbuffer must be larger than
402 * anything we ever want to print.
403 */
Wolfgang Denk4d6402b2011-10-29 09:42:23 +0000404 vsprintf(printbuffer, format, args);
Wolfgang Denk50da8372011-10-29 09:42:22 +0000405 va_end(args);
wdenka042ac82002-09-12 22:36:57 +0000406
407 /* Send to the stdout file */
Heiko Schochere92372c2011-10-12 01:18:05 +0000408 puts(printbuffer);
wdenka042ac82002-09-12 22:36:57 +0000409
410 return 0;
411}
412
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200413#ifdef CONFIG_NEEDS_MANUAL_RELOC
Heiko Schochere92372c2011-10-12 01:18:05 +0000414void post_reloc(void)
wdenka042ac82002-09-12 22:36:57 +0000415{
wdenka042ac82002-09-12 22:36:57 +0000416 unsigned int i;
417
418 /*
419 * We have to relocate the test table manually
420 */
421 for (i = 0; i < post_list_size; i++) {
422 ulong addr;
423 struct post_test *test = post_list + i;
424
425 if (test->name) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000426 addr = (ulong)(test->name) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000427 test->name = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000428 }
429
430 if (test->cmd) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000431 addr = (ulong)(test->cmd) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000432 test->cmd = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000433 }
434
435 if (test->desc) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000436 addr = (ulong)(test->desc) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000437 test->desc = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000438 }
439
440 if (test->test) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000441 addr = (ulong)(test->test) + gd->reloc_off;
wdenka042ac82002-09-12 22:36:57 +0000442 test->test = (int (*)(int flags)) addr;
443 }
wdenk4532cb62003-04-27 22:52:51 +0000444
445 if (test->init_f) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000446 addr = (ulong)(test->init_f) + gd->reloc_off;
wdenk4532cb62003-04-27 22:52:51 +0000447 test->init_f = (int (*)(void)) addr;
448 }
449
450 if (test->reloc) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000451 addr = (ulong)(test->reloc) + gd->reloc_off;
wdenk4532cb62003-04-27 22:52:51 +0000452 test->reloc = (void (*)(void)) addr;
wdenk8bde7f72003-06-27 21:31:46 +0000453
wdenk4532cb62003-04-27 22:52:51 +0000454 test->reloc();
455 }
wdenka042ac82002-09-12 22:36:57 +0000456 }
457}
Peter Tyser521af042009-09-21 11:20:36 -0500458#endif
wdenka042ac82002-09-12 22:36:57 +0000459
wdenk4532cb62003-04-27 22:52:51 +0000460
461/*
462 * Some tests (e.g. SYSMON) need the time when post_init_f started,
463 * but we cannot use get_timer() at this point.
464 *
465 * On PowerPC we implement it using the timebase register.
466 */
Heiko Schochere92372c2011-10-12 01:18:05 +0000467unsigned long post_time_ms(unsigned long base)
wdenk4532cb62003-04-27 22:52:51 +0000468{
Tom Riniea3310e2017-03-14 11:08:10 -0400469#if defined(CONFIG_PPC) || defined(CONFIG_ARM)
Christian Rieschc90a4dd2011-12-09 16:54:02 +0100470 return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ)
Heiko Schochere92372c2011-10-12 01:18:05 +0000471 - base;
wdenk4532cb62003-04-27 22:52:51 +0000472#else
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100473#warning "Not implemented yet"
wdenk4532cb62003-04-27 22:52:51 +0000474 return 0; /* Not implemented yet */
475#endif
476}