blob: 6c7902ad0c7ba85bd078fbc0aa6bd2adf53eff37 [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
Wolfgang Denkd87080b2006-03-31 18:32:53 +020018DECLARE_GLOBAL_DATA_PTR;
19
wdenka042ac82002-09-12 22:36:57 +000020#define POST_MAX_NUMBER 32
21
22#define BOOTMODE_MAGIC 0xDEAD0000
23
Heiko Schochere92372c2011-10-12 01:18:05 +000024int post_init_f(void)
wdenk4532cb62003-04-27 22:52:51 +000025{
wdenk4532cb62003-04-27 22:52:51 +000026 int res = 0;
27 unsigned int i;
28
29 for (i = 0; i < post_list_size; i++) {
30 struct post_test *test = post_list + i;
31
Wolfgang Denk50da8372011-10-29 09:42:22 +000032 if (test->init_f && test->init_f())
wdenk4532cb62003-04-27 22:52:51 +000033 res = -1;
wdenk4532cb62003-04-27 22:52:51 +000034 }
wdenk8bde7f72003-06-27 21:31:46 +000035
wdenk4532cb62003-04-27 22:52:51 +000036 gd->post_init_f_time = post_time_ms(0);
37 if (!gd->post_init_f_time)
Heiko Schochere92372c2011-10-12 01:18:05 +000038 printf("%s: post_time_ms not implemented\n", __FILE__);
wdenk4532cb62003-04-27 22:52:51 +000039
40 return res;
41}
42
Stefan Roese39ff7d52009-12-03 06:24:30 +010043/*
44 * Supply a default implementation for post_hotkeys_pressed() for boards
45 * without hotkey support. We always return 0 here, so that the
46 * long-running tests won't be started.
47 *
48 * Boards with hotkey support can override this weak default function
49 * by defining one in their board specific code.
50 */
Jeroen Hofstee002ad7b2014-10-08 22:57:25 +020051__weak int post_hotkeys_pressed(void)
Stefan Roese39ff7d52009-12-03 06:24:30 +010052{
Mike Frysinger9146d132011-05-10 07:01:21 +000053#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
54 int ret;
55 unsigned gpio = CONFIG_SYS_POST_HOTKEYS_GPIO;
56
57 ret = gpio_request(gpio, "hotkeys");
58 if (ret) {
59 printf("POST: gpio hotkey request failed\n");
60 return 0;
61 }
62
63 gpio_direction_input(gpio);
64 ret = gpio_get_value(gpio);
65 gpio_free(gpio);
66
67 return ret;
68#endif
69
Stefan Roese39ff7d52009-12-03 06:24:30 +010070 return 0; /* No hotkeys supported */
71}
Stefan Roese39ff7d52009-12-03 06:24:30 +010072
Heiko Schochere92372c2011-10-12 01:18:05 +000073void post_bootmode_init(void)
wdenka042ac82002-09-12 22:36:57 +000074{
Heiko Schochere92372c2011-10-12 01:18:05 +000075 int bootmode = post_bootmode_get(0);
wdenk27b207f2003-07-24 23:38:38 +000076 int newword;
wdenk42d1f032003-10-15 23:53:47 +000077
Heiko Schochere92372c2011-10-12 01:18:05 +000078 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST))
wdenk27b207f2003-07-24 23:38:38 +000079 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
Heiko Schochere92372c2011-10-12 01:18:05 +000080 else if (bootmode == 0)
wdenk27b207f2003-07-24 23:38:38 +000081 newword = BOOTMODE_MAGIC | POST_POWERON;
Heiko Schochere92372c2011-10-12 01:18:05 +000082 else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST)
wdenk27b207f2003-07-24 23:38:38 +000083 newword = BOOTMODE_MAGIC | POST_NORMAL;
Heiko Schochere92372c2011-10-12 01:18:05 +000084 else
wdenk27b207f2003-07-24 23:38:38 +000085 /* Use old value */
Wolfgang Denk50da8372011-10-29 09:42:22 +000086 newword = post_word_load() & ~POST_COLDBOOT;
wdenka042ac82002-09-12 22:36:57 +000087
wdenk27b207f2003-07-24 23:38:38 +000088 if (bootmode == 0)
wdenk27b207f2003-07-24 23:38:38 +000089 /* We are booting after power-on */
90 newword |= POST_COLDBOOT;
wdenk27b207f2003-07-24 23:38:38 +000091
Heiko Schochere92372c2011-10-12 01:18:05 +000092 post_word_store(newword);
wdenk27b207f2003-07-24 23:38:38 +000093
wdenk228f29a2002-12-08 09:53:23 +000094 /* Reset activity record */
95 gd->post_log_word = 0;
Valentin Longchamp79843952011-08-03 02:37:01 +000096 gd->post_log_res = 0;
wdenka042ac82002-09-12 22:36:57 +000097}
98
Heiko Schochere92372c2011-10-12 01:18:05 +000099int post_bootmode_get(unsigned int *last_test)
wdenka042ac82002-09-12 22:36:57 +0000100{
Heiko Schochere92372c2011-10-12 01:18:05 +0000101 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000102 int bootmode;
103
Heiko Schochere92372c2011-10-12 01:18:05 +0000104 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC)
wdenka042ac82002-09-12 22:36:57 +0000105 return 0;
wdenka042ac82002-09-12 22:36:57 +0000106
wdenk27b207f2003-07-24 23:38:38 +0000107 bootmode = word & 0x7F;
wdenka042ac82002-09-12 22:36:57 +0000108
Heiko Schochere92372c2011-10-12 01:18:05 +0000109 if (last_test && (bootmode & POST_POWERTEST))
wdenka042ac82002-09-12 22:36:57 +0000110 *last_test = (word >> 8) & 0xFF;
wdenka042ac82002-09-12 22:36:57 +0000111
112 return bootmode;
113}
114
wdenk228f29a2002-12-08 09:53:23 +0000115/* POST tests run before relocation only mark status bits .... */
Heiko Schochere92372c2011-10-12 01:18:05 +0000116static void post_log_mark_start(unsigned long testid)
wdenk228f29a2002-12-08 09:53:23 +0000117{
Valentin Longchamp79843952011-08-03 02:37:01 +0000118 gd->post_log_word |= testid;
wdenk228f29a2002-12-08 09:53:23 +0000119}
120
Heiko Schochere92372c2011-10-12 01:18:05 +0000121static void post_log_mark_succ(unsigned long testid)
wdenk228f29a2002-12-08 09:53:23 +0000122{
Valentin Longchamp79843952011-08-03 02:37:01 +0000123 gd->post_log_res |= testid;
wdenk228f29a2002-12-08 09:53:23 +0000124}
125
126/* ... and the messages are output once we are relocated */
Heiko Schochere92372c2011-10-12 01:18:05 +0000127void post_output_backlog(void)
wdenk228f29a2002-12-08 09:53:23 +0000128{
wdenk228f29a2002-12-08 09:53:23 +0000129 int j;
130
131 for (j = 0; j < post_list_size; j++) {
Valentin Longchamp79843952011-08-03 02:37:01 +0000132 if (gd->post_log_word & (post_list[j].testid)) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000133 post_log("POST %s ", post_list[j].cmd);
Valentin Longchamp79843952011-08-03 02:37:01 +0000134 if (gd->post_log_res & post_list[j].testid)
Wolfgang Denk50da8372011-10-29 09:42:22 +0000135 post_log("PASSED\n");
wdenk63e73c92004-02-23 22:22:28 +0000136 else {
Heiko Schochere92372c2011-10-12 01:18:05 +0000137 post_log("FAILED\n");
Simon Glass770605e2012-02-13 13:51:18 +0000138 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
wdenk63e73c92004-02-23 22:22:28 +0000139 }
wdenk228f29a2002-12-08 09:53:23 +0000140 }
141 }
142}
143
Heiko Schochere92372c2011-10-12 01:18:05 +0000144static void post_bootmode_test_on(unsigned int last_test)
wdenka042ac82002-09-12 22:36:57 +0000145{
Heiko Schochere92372c2011-10-12 01:18:05 +0000146 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000147
148 word |= POST_POWERTEST;
149
150 word |= (last_test & 0xFF) << 8;
151
Heiko Schochere92372c2011-10-12 01:18:05 +0000152 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000153}
154
Heiko Schochere92372c2011-10-12 01:18:05 +0000155static void post_bootmode_test_off(void)
wdenka042ac82002-09-12 22:36:57 +0000156{
Heiko Schochere92372c2011-10-12 01:18:05 +0000157 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000158
159 word &= ~POST_POWERTEST;
160
Heiko Schochere92372c2011-10-12 01:18:05 +0000161 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000162}
163
Valentin Longchamp212a0ca2011-08-03 02:37:02 +0000164#ifndef CONFIG_POST_SKIP_ENV_FLAGS
165static void post_get_env_flags(int *test_flags)
wdenka042ac82002-09-12 22:36:57 +0000166{
Yuri Tikhonove262efe2008-02-04 14:11:03 +0100167 int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST,
168 POST_CRITICAL };
169 char *var[] = { "post_poweron", "post_normal", "post_slowtest",
170 "post_critical" };
Mike Frysingerd2397812011-05-10 07:28:35 +0000171 int varnum = ARRAY_SIZE(var);
wdenka042ac82002-09-12 22:36:57 +0000172 char list[128]; /* long enough for POST list */
173 char *name;
174 char *s;
175 int last;
176 int i, j;
177
wdenka042ac82002-09-12 22:36:57 +0000178 for (i = 0; i < varnum; i++) {
Simon Glass00caae62017-08-03 12:22:12 -0600179 if (env_get_f(var[i], list, sizeof(list)) <= 0)
wdenka042ac82002-09-12 22:36:57 +0000180 continue;
181
Wolfgang Denk50da8372011-10-29 09:42:22 +0000182 for (j = 0; j < post_list_size; j++)
wdenka042ac82002-09-12 22:36:57 +0000183 test_flags[j] &= ~flag[i];
wdenka042ac82002-09-12 22:36:57 +0000184
185 last = 0;
186 name = list;
187 while (!last) {
188 while (*name && *name == ' ')
189 name++;
190 if (*name == 0)
191 break;
192 s = name + 1;
193 while (*s && *s != ' ')
194 s++;
195 if (*s == 0)
196 last = 1;
197 else
198 *s = 0;
199
200 for (j = 0; j < post_list_size; j++) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000201 if (strcmp(post_list[j].cmd, name) == 0) {
wdenka042ac82002-09-12 22:36:57 +0000202 test_flags[j] |= flag[i];
203 break;
204 }
205 }
206
Heiko Schochere92372c2011-10-12 01:18:05 +0000207 if (j == post_list_size)
Wolfgang Denk50da8372011-10-29 09:42:22 +0000208 printf("No such test: %s\n", name);
wdenka042ac82002-09-12 22:36:57 +0000209
210 name = s + 1;
211 }
212 }
Valentin Longchamp212a0ca2011-08-03 02:37:02 +0000213}
214#endif
215
216static void post_get_flags(int *test_flags)
217{
218 int j;
219
220 for (j = 0; j < post_list_size; j++)
221 test_flags[j] = post_list[j].flags;
222
223#ifndef CONFIG_POST_SKIP_ENV_FLAGS
224 post_get_env_flags(test_flags);
225#endif
wdenk6dff5522003-07-15 07:45:49 +0000226
Heiko Schochere92372c2011-10-12 01:18:05 +0000227 for (j = 0; j < post_list_size; j++)
228 if (test_flags[j] & POST_POWERON)
wdenk6dff5522003-07-15 07:45:49 +0000229 test_flags[j] |= POST_SLOWTEST;
wdenka042ac82002-09-12 22:36:57 +0000230}
231
Jeroen Hofstee002ad7b2014-10-08 22:57:25 +0200232__weak void show_post_progress(unsigned int test_num, int before, int result)
Michael Zaidmane070a562010-03-01 11:47:36 +0200233{
234}
Michael Zaidmane070a562010-03-01 11:47:36 +0200235
Heiko Schochere92372c2011-10-12 01:18:05 +0000236static int post_run_single(struct post_test *test,
wdenka042ac82002-09-12 22:36:57 +0000237 int test_flags, int flags, unsigned int i)
238{
239 if ((flags & test_flags & POST_ALWAYS) &&
240 (flags & test_flags & POST_MEM)) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000241 WATCHDOG_RESET();
wdenka042ac82002-09-12 22:36:57 +0000242
243 if (!(flags & POST_REBOOT)) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000244 if ((test_flags & POST_REBOOT) &&
245 !(flags & POST_MANUAL)) {
246 post_bootmode_test_on(
Yuri Tikhonove262efe2008-02-04 14:11:03 +0100247 (gd->flags & GD_FLG_POSTFAIL) ?
248 POST_FAIL_SAVE | i : i);
wdenka042ac82002-09-12 22:36:57 +0000249 }
250
wdenk228f29a2002-12-08 09:53:23 +0000251 if (test_flags & POST_PREREL)
Heiko Schochere92372c2011-10-12 01:18:05 +0000252 post_log_mark_start(test->testid);
wdenk228f29a2002-12-08 09:53:23 +0000253 else
Heiko Schochere92372c2011-10-12 01:18:05 +0000254 post_log("POST %s ", test->cmd);
wdenka042ac82002-09-12 22:36:57 +0000255 }
256
Michael Zaidmane070a562010-03-01 11:47:36 +0200257 show_post_progress(i, POST_BEFORE, POST_FAILED);
258
wdenk228f29a2002-12-08 09:53:23 +0000259 if (test_flags & POST_PREREL) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000260 if ((*test->test)(flags) == 0) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000261 post_log_mark_succ(test->testid);
Michael Zaidmane070a562010-03-01 11:47:36 +0200262 show_post_progress(i, POST_AFTER, POST_PASSED);
Wolfgang Denk50da8372011-10-29 09:42:22 +0000263 } else {
Michael Zaidmane070a562010-03-01 11:47:36 +0200264 show_post_progress(i, POST_AFTER, POST_FAILED);
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200265 if (test_flags & POST_CRITICAL)
266 gd->flags |= GD_FLG_POSTFAIL;
267 if (test_flags & POST_STOP)
268 gd->flags |= GD_FLG_POSTSTOP;
269 }
wdenk228f29a2002-12-08 09:53:23 +0000270 } else {
James Kosin975afc32011-07-14 08:15:06 +0000271 if ((*test->test)(flags) != 0) {
272 post_log("FAILED\n");
Simon Glass770605e2012-02-13 13:51:18 +0000273 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
James Kosin975afc32011-07-14 08:15:06 +0000274 show_post_progress(i, POST_AFTER, POST_FAILED);
275 if (test_flags & POST_CRITICAL)
276 gd->flags |= GD_FLG_POSTFAIL;
277 if (test_flags & POST_STOP)
278 gd->flags |= GD_FLG_POSTSTOP;
279 } else {
280 post_log("PASSED\n");
281 show_post_progress(i, POST_AFTER, POST_PASSED);
282 }
wdenk228f29a2002-12-08 09:53:23 +0000283 }
wdenka042ac82002-09-12 22:36:57 +0000284
Wolfgang Denk50da8372011-10-29 09:42:22 +0000285 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL))
Heiko Schochere92372c2011-10-12 01:18:05 +0000286 post_bootmode_test_off();
wdenka042ac82002-09-12 22:36:57 +0000287
288 return 0;
289 } else {
290 return -1;
291 }
292}
293
Wolfgang Denk50da8372011-10-29 09:42:22 +0000294int post_run(char *name, int flags)
wdenka042ac82002-09-12 22:36:57 +0000295{
296 unsigned int i;
297 int test_flags[POST_MAX_NUMBER];
298
Heiko Schochere92372c2011-10-12 01:18:05 +0000299 post_get_flags(test_flags);
wdenka042ac82002-09-12 22:36:57 +0000300
301 if (name == NULL) {
302 unsigned int last;
303
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200304 if (gd->flags & GD_FLG_POSTSTOP)
305 return 0;
306
Heiko Schochere92372c2011-10-12 01:18:05 +0000307 if (post_bootmode_get(&last) & POST_POWERTEST) {
Yuri Tikhonove262efe2008-02-04 14:11:03 +0100308 if (last & POST_FAIL_SAVE) {
309 last &= ~POST_FAIL_SAVE;
310 gd->flags |= GD_FLG_POSTFAIL;
311 }
wdenka042ac82002-09-12 22:36:57 +0000312 if (last < post_list_size &&
313 (flags & test_flags[last] & POST_ALWAYS) &&
314 (flags & test_flags[last] & POST_MEM)) {
315
Heiko Schochere92372c2011-10-12 01:18:05 +0000316 post_run_single(post_list + last,
wdenkea909b72002-11-21 23:11:29 +0000317 test_flags[last],
318 flags | POST_REBOOT, last);
wdenka042ac82002-09-12 22:36:57 +0000319
320 for (i = last + 1; i < post_list_size; i++) {
Yuri Tikhonov28a38502008-05-08 15:45:26 +0200321 if (gd->flags & GD_FLG_POSTSTOP)
322 break;
Heiko Schochere92372c2011-10-12 01:18:05 +0000323 post_run_single(post_list + i,
wdenkea909b72002-11-21 23:11:29 +0000324 test_flags[i],
325 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000326 }
327 }
328 } else {
329 for (i = 0; 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
338 return 0;
339 } else {
340 for (i = 0; i < post_list_size; i++) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000341 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000342 break;
343 }
344
345 if (i < post_list_size) {
Sascha Laue5744ddc2008-05-30 09:48:14 +0200346 WATCHDOG_RESET();
Heiko Schochere92372c2011-10-12 01:18:05 +0000347 return post_run_single(post_list + i,
wdenka042ac82002-09-12 22:36:57 +0000348 test_flags[i],
349 flags, i);
350 } else {
351 return -1;
352 }
353 }
354}
355
Heiko Schochere92372c2011-10-12 01:18:05 +0000356static int post_info_single(struct post_test *test, int full)
wdenka042ac82002-09-12 22:36:57 +0000357{
358 if (test->flags & POST_MANUAL) {
359 if (full)
Heiko Schochere92372c2011-10-12 01:18:05 +0000360 printf("%s - %s\n"
wdenka042ac82002-09-12 22:36:57 +0000361 " %s\n", test->cmd, test->name, test->desc);
362 else
Heiko Schochere92372c2011-10-12 01:18:05 +0000363 printf(" %-15s - %s\n", test->cmd, test->name);
wdenka042ac82002-09-12 22:36:57 +0000364
365 return 0;
366 } else {
367 return -1;
368 }
369}
370
Wolfgang Denk50da8372011-10-29 09:42:22 +0000371int post_info(char *name)
wdenka042ac82002-09-12 22:36:57 +0000372{
373 unsigned int i;
374
375 if (name == NULL) {
Heiko Schochere92372c2011-10-12 01:18:05 +0000376 for (i = 0; i < post_list_size; i++)
377 post_info_single(post_list + i, 0);
wdenka042ac82002-09-12 22:36:57 +0000378
379 return 0;
380 } else {
381 for (i = 0; i < post_list_size; i++) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000382 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000383 break;
384 }
385
Wolfgang Denk50da8372011-10-29 09:42:22 +0000386 if (i < post_list_size)
Heiko Schochere92372c2011-10-12 01:18:05 +0000387 return post_info_single(post_list + i, 1);
Wolfgang Denk50da8372011-10-29 09:42:22 +0000388 else
wdenka042ac82002-09-12 22:36:57 +0000389 return -1;
wdenka042ac82002-09-12 22:36:57 +0000390 }
391}
392
Heiko Schochere92372c2011-10-12 01:18:05 +0000393int post_log(char *format, ...)
wdenka042ac82002-09-12 22:36:57 +0000394{
395 va_list args;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200396 char printbuffer[CONFIG_SYS_PBSIZE];
wdenka042ac82002-09-12 22:36:57 +0000397
Wolfgang Denk50da8372011-10-29 09:42:22 +0000398 va_start(args, format);
wdenka042ac82002-09-12 22:36:57 +0000399
400 /* For this to work, printbuffer must be larger than
401 * anything we ever want to print.
402 */
Wolfgang Denk4d6402b2011-10-29 09:42:23 +0000403 vsprintf(printbuffer, format, args);
Wolfgang Denk50da8372011-10-29 09:42:22 +0000404 va_end(args);
wdenka042ac82002-09-12 22:36:57 +0000405
406 /* Send to the stdout file */
Heiko Schochere92372c2011-10-12 01:18:05 +0000407 puts(printbuffer);
wdenka042ac82002-09-12 22:36:57 +0000408
409 return 0;
410}
411
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200412#ifdef CONFIG_NEEDS_MANUAL_RELOC
Heiko Schochere92372c2011-10-12 01:18:05 +0000413void post_reloc(void)
wdenka042ac82002-09-12 22:36:57 +0000414{
wdenka042ac82002-09-12 22:36:57 +0000415 unsigned int i;
416
417 /*
418 * We have to relocate the test table manually
419 */
420 for (i = 0; i < post_list_size; i++) {
421 ulong addr;
422 struct post_test *test = post_list + i;
423
424 if (test->name) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000425 addr = (ulong)(test->name) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000426 test->name = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000427 }
428
429 if (test->cmd) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000430 addr = (ulong)(test->cmd) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000431 test->cmd = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000432 }
433
434 if (test->desc) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000435 addr = (ulong)(test->desc) + gd->reloc_off;
Heiko Schochere92372c2011-10-12 01:18:05 +0000436 test->desc = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000437 }
438
439 if (test->test) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000440 addr = (ulong)(test->test) + gd->reloc_off;
wdenka042ac82002-09-12 22:36:57 +0000441 test->test = (int (*)(int flags)) addr;
442 }
wdenk4532cb62003-04-27 22:52:51 +0000443
444 if (test->init_f) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000445 addr = (ulong)(test->init_f) + gd->reloc_off;
wdenk4532cb62003-04-27 22:52:51 +0000446 test->init_f = (int (*)(void)) addr;
447 }
448
449 if (test->reloc) {
Wolfgang Denk50da8372011-10-29 09:42:22 +0000450 addr = (ulong)(test->reloc) + gd->reloc_off;
wdenk4532cb62003-04-27 22:52:51 +0000451 test->reloc = (void (*)(void)) addr;
wdenk8bde7f72003-06-27 21:31:46 +0000452
wdenk4532cb62003-04-27 22:52:51 +0000453 test->reloc();
454 }
wdenka042ac82002-09-12 22:36:57 +0000455 }
456}
Peter Tyser521af042009-09-21 11:20:36 -0500457#endif
wdenka042ac82002-09-12 22:36:57 +0000458
wdenk4532cb62003-04-27 22:52:51 +0000459
460/*
461 * Some tests (e.g. SYSMON) need the time when post_init_f started,
462 * but we cannot use get_timer() at this point.
463 *
464 * On PowerPC we implement it using the timebase register.
465 */
Heiko Schochere92372c2011-10-12 01:18:05 +0000466unsigned long post_time_ms(unsigned long base)
wdenk4532cb62003-04-27 22:52:51 +0000467{
Tom Riniea3310e2017-03-14 11:08:10 -0400468#if defined(CONFIG_PPC) || defined(CONFIG_ARM)
Christian Rieschc90a4dd2011-12-09 16:54:02 +0100469 return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ)
Heiko Schochere92372c2011-10-12 01:18:05 +0000470 - base;
wdenk4532cb62003-04-27 22:52:51 +0000471#else
Wolfgang Denkad5bb452007-03-06 18:08:43 +0100472#warning "Not implemented yet"
wdenk4532cb62003-04-27 22:52:51 +0000473 return 0; /* Not implemented yet */
474#endif
475}