blob: f27138ddaaf3bba4fa165e20c13de945cbbd85d4 [file] [log] [blame]
Tom Rini10e47792018-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 Glassdb229612019-08-01 09:46:42 -06008#include <env.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +02009#include <stdio_dev.h>
Simon Glass495a5dc2019-11-14 12:57:30 -070010#include <time.h>
wdenka042ac82002-09-12 22:36:57 +000011#include <watchdog.h>
Christian Rieschbb968ec2011-12-09 16:54:02 +010012#include <div64.h>
wdenka042ac82002-09-12 22:36:57 +000013#include <post.h>
14
Mike Frysinger2073edd2011-05-10 07:01:21 +000015#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
16#include <asm/gpio.h>
17#endif
18
Wolfgang Denk6405a152006-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 Schocher51ee5912011-10-12 01:18:05 +000025int post_init_f(void)
wdenkc08f1582003-04-27 22:52:51 +000026{
wdenkc08f1582003-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 Denkf7a49f12011-10-29 09:42:22 +000033 if (test->init_f && test->init_f())
wdenkc08f1582003-04-27 22:52:51 +000034 res = -1;
wdenkc08f1582003-04-27 22:52:51 +000035 }
wdenk57b2d802003-06-27 21:31:46 +000036
wdenkc08f1582003-04-27 22:52:51 +000037 gd->post_init_f_time = post_time_ms(0);
38 if (!gd->post_init_f_time)
Heiko Schocher51ee5912011-10-12 01:18:05 +000039 printf("%s: post_time_ms not implemented\n", __FILE__);
wdenkc08f1582003-04-27 22:52:51 +000040
41 return res;
42}
43
Stefan Roesef0a15c52009-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 Hofstee4e5f9e62014-10-08 22:57:25 +020052__weak int post_hotkeys_pressed(void)
Stefan Roesef0a15c52009-12-03 06:24:30 +010053{
Mike Frysinger2073edd2011-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 Roesef0a15c52009-12-03 06:24:30 +010071 return 0; /* No hotkeys supported */
72}
Stefan Roesef0a15c52009-12-03 06:24:30 +010073
Heiko Schocher51ee5912011-10-12 01:18:05 +000074void post_bootmode_init(void)
wdenka042ac82002-09-12 22:36:57 +000075{
Heiko Schocher51ee5912011-10-12 01:18:05 +000076 int bootmode = post_bootmode_get(0);
wdenk874ac262003-07-24 23:38:38 +000077 int newword;
wdenk9c53f402003-10-15 23:53:47 +000078
Heiko Schocher51ee5912011-10-12 01:18:05 +000079 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST))
wdenk874ac262003-07-24 23:38:38 +000080 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
Heiko Schocher51ee5912011-10-12 01:18:05 +000081 else if (bootmode == 0)
wdenk874ac262003-07-24 23:38:38 +000082 newword = BOOTMODE_MAGIC | POST_POWERON;
Heiko Schocher51ee5912011-10-12 01:18:05 +000083 else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST)
wdenk874ac262003-07-24 23:38:38 +000084 newword = BOOTMODE_MAGIC | POST_NORMAL;
Heiko Schocher51ee5912011-10-12 01:18:05 +000085 else
wdenk874ac262003-07-24 23:38:38 +000086 /* Use old value */
Wolfgang Denkf7a49f12011-10-29 09:42:22 +000087 newword = post_word_load() & ~POST_COLDBOOT;
wdenk874ac262003-07-24 23:38:38 +000088
89 if (bootmode == 0)
wdenk874ac262003-07-24 23:38:38 +000090 /* We are booting after power-on */
91 newword |= POST_COLDBOOT;
wdenka042ac82002-09-12 22:36:57 +000092
Heiko Schocher51ee5912011-10-12 01:18:05 +000093 post_word_store(newword);
wdenk874ac262003-07-24 23:38:38 +000094
wdenk9dfa8d12002-12-08 09:53:23 +000095 /* Reset activity record */
96 gd->post_log_word = 0;
Valentin Longchampb9181732011-08-03 02:37:01 +000097 gd->post_log_res = 0;
wdenka042ac82002-09-12 22:36:57 +000098}
99
Heiko Schocher51ee5912011-10-12 01:18:05 +0000100int post_bootmode_get(unsigned int *last_test)
wdenka042ac82002-09-12 22:36:57 +0000101{
Heiko Schocher51ee5912011-10-12 01:18:05 +0000102 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000103 int bootmode;
104
Heiko Schocher51ee5912011-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
wdenk874ac262003-07-24 23:38:38 +0000108 bootmode = word & 0x7F;
wdenka042ac82002-09-12 22:36:57 +0000109
Heiko Schocher51ee5912011-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
wdenk9dfa8d12002-12-08 09:53:23 +0000116/* POST tests run before relocation only mark status bits .... */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000117static void post_log_mark_start(unsigned long testid)
wdenk9dfa8d12002-12-08 09:53:23 +0000118{
Valentin Longchampb9181732011-08-03 02:37:01 +0000119 gd->post_log_word |= testid;
wdenk9dfa8d12002-12-08 09:53:23 +0000120}
121
Heiko Schocher51ee5912011-10-12 01:18:05 +0000122static void post_log_mark_succ(unsigned long testid)
wdenk9dfa8d12002-12-08 09:53:23 +0000123{
Valentin Longchampb9181732011-08-03 02:37:01 +0000124 gd->post_log_res |= testid;
wdenk9dfa8d12002-12-08 09:53:23 +0000125}
126
127/* ... and the messages are output once we are relocated */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000128void post_output_backlog(void)
wdenk9dfa8d12002-12-08 09:53:23 +0000129{
wdenk9dfa8d12002-12-08 09:53:23 +0000130 int j;
131
132 for (j = 0; j < post_list_size; j++) {
Valentin Longchampb9181732011-08-03 02:37:01 +0000133 if (gd->post_log_word & (post_list[j].testid)) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000134 post_log("POST %s ", post_list[j].cmd);
Valentin Longchampb9181732011-08-03 02:37:01 +0000135 if (gd->post_log_res & post_list[j].testid)
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000136 post_log("PASSED\n");
wdenke97d3d92004-02-23 22:22:28 +0000137 else {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000138 post_log("FAILED\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000139 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
wdenke97d3d92004-02-23 22:22:28 +0000140 }
wdenk9dfa8d12002-12-08 09:53:23 +0000141 }
142 }
143}
144
Heiko Schocher51ee5912011-10-12 01:18:05 +0000145static void post_bootmode_test_on(unsigned int last_test)
wdenka042ac82002-09-12 22:36:57 +0000146{
Heiko Schocher51ee5912011-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 Schocher51ee5912011-10-12 01:18:05 +0000153 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000154}
155
Heiko Schocher51ee5912011-10-12 01:18:05 +0000156static void post_bootmode_test_off(void)
wdenka042ac82002-09-12 22:36:57 +0000157{
Heiko Schocher51ee5912011-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 Schocher51ee5912011-10-12 01:18:05 +0000162 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000163}
164
Valentin Longchampcfc88802011-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 Tikhonov6a068a12008-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 Frysinger83a687b2011-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 Glass64b723f2017-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 Denkf7a49f12011-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 Denkf7a49f12011-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 Schocher51ee5912011-10-12 01:18:05 +0000208 if (j == post_list_size)
Wolfgang Denkf7a49f12011-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 Longchampcfc88802011-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
wdenkca9bc762003-07-15 07:45:49 +0000227
Heiko Schocher51ee5912011-10-12 01:18:05 +0000228 for (j = 0; j < post_list_size; j++)
229 if (test_flags[j] & POST_POWERON)
wdenkca9bc762003-07-15 07:45:49 +0000230 test_flags[j] |= POST_SLOWTEST;
wdenka042ac82002-09-12 22:36:57 +0000231}
232
Jeroen Hofstee4e5f9e62014-10-08 22:57:25 +0200233__weak void show_post_progress(unsigned int test_num, int before, int result)
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200234{
235}
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200236
Heiko Schocher51ee5912011-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 Denkf7a49f12011-10-29 09:42:22 +0000242 WATCHDOG_RESET();
wdenka042ac82002-09-12 22:36:57 +0000243
244 if (!(flags & POST_REBOOT)) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000245 if ((test_flags & POST_REBOOT) &&
246 !(flags & POST_MANUAL)) {
247 post_bootmode_test_on(
Yuri Tikhonov6a068a12008-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
wdenk9dfa8d12002-12-08 09:53:23 +0000252 if (test_flags & POST_PREREL)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000253 post_log_mark_start(test->testid);
wdenk9dfa8d12002-12-08 09:53:23 +0000254 else
Heiko Schocher51ee5912011-10-12 01:18:05 +0000255 post_log("POST %s ", test->cmd);
wdenka042ac82002-09-12 22:36:57 +0000256 }
257
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200258 show_post_progress(i, POST_BEFORE, POST_FAILED);
259
wdenk9dfa8d12002-12-08 09:53:23 +0000260 if (test_flags & POST_PREREL) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000261 if ((*test->test)(flags) == 0) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000262 post_log_mark_succ(test->testid);
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200263 show_post_progress(i, POST_AFTER, POST_PASSED);
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000264 } else {
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200265 show_post_progress(i, POST_AFTER, POST_FAILED);
Yuri Tikhonovbc439b02008-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 }
wdenk9dfa8d12002-12-08 09:53:23 +0000271 } else {
James Kosine7deffc2011-07-14 08:15:06 +0000272 if ((*test->test)(flags) != 0) {
273 post_log("FAILED\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000274 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
James Kosine7deffc2011-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 }
wdenk9dfa8d12002-12-08 09:53:23 +0000284 }
wdenka042ac82002-09-12 22:36:57 +0000285
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000286 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL))
Heiko Schocher51ee5912011-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 Denkf7a49f12011-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 Schocher51ee5912011-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 Tikhonovbc439b02008-05-08 15:45:26 +0200305 if (gd->flags & GD_FLG_POSTSTOP)
306 return 0;
307
Heiko Schocher51ee5912011-10-12 01:18:05 +0000308 if (post_bootmode_get(&last) & POST_POWERTEST) {
Yuri Tikhonov6a068a12008-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 Schocher51ee5912011-10-12 01:18:05 +0000317 post_run_single(post_list + last,
wdenk2029f4d2002-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 Tikhonovbc439b02008-05-08 15:45:26 +0200322 if (gd->flags & GD_FLG_POSTSTOP)
323 break;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000324 post_run_single(post_list + i,
wdenk2029f4d2002-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 Tikhonovbc439b02008-05-08 15:45:26 +0200331 if (gd->flags & GD_FLG_POSTSTOP)
332 break;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000333 post_run_single(post_list + i,
wdenk2029f4d2002-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 Denkf7a49f12011-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 Laue00150532008-05-30 09:48:14 +0200347 WATCHDOG_RESET();
Heiko Schocher51ee5912011-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 Schocher51ee5912011-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 Schocher51ee5912011-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 Schocher51ee5912011-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 Denkf7a49f12011-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 Schocher51ee5912011-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 Denkf7a49f12011-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 Denkf7a49f12011-10-29 09:42:22 +0000387 if (i < post_list_size)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000388 return post_info_single(post_list + i, 1);
Wolfgang Denkf7a49f12011-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 Schocher51ee5912011-10-12 01:18:05 +0000394int post_log(char *format, ...)
wdenka042ac82002-09-12 22:36:57 +0000395{
396 va_list args;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200397 char printbuffer[CONFIG_SYS_PBSIZE];
wdenka042ac82002-09-12 22:36:57 +0000398
Wolfgang Denkf7a49f12011-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 Denkbedfa0a2011-10-29 09:42:23 +0000404 vsprintf(printbuffer, format, args);
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000405 va_end(args);
wdenka042ac82002-09-12 22:36:57 +0000406
407 /* Send to the stdout file */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000408 puts(printbuffer);
wdenka042ac82002-09-12 22:36:57 +0000409
410 return 0;
411}
412
Wolfgang Denkd0813e52010-10-28 20:00:11 +0200413#ifdef CONFIG_NEEDS_MANUAL_RELOC
Heiko Schocher51ee5912011-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 Denkf7a49f12011-10-29 09:42:22 +0000426 addr = (ulong)(test->name) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000427 test->name = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000428 }
429
430 if (test->cmd) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000431 addr = (ulong)(test->cmd) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000432 test->cmd = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000433 }
434
435 if (test->desc) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000436 addr = (ulong)(test->desc) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000437 test->desc = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000438 }
439
440 if (test->test) {
Wolfgang Denkf7a49f12011-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 }
wdenkc08f1582003-04-27 22:52:51 +0000444
445 if (test->init_f) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000446 addr = (ulong)(test->init_f) + gd->reloc_off;
wdenkc08f1582003-04-27 22:52:51 +0000447 test->init_f = (int (*)(void)) addr;
448 }
449
450 if (test->reloc) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000451 addr = (ulong)(test->reloc) + gd->reloc_off;
wdenkc08f1582003-04-27 22:52:51 +0000452 test->reloc = (void (*)(void)) addr;
wdenk57b2d802003-06-27 21:31:46 +0000453
wdenkc08f1582003-04-27 22:52:51 +0000454 test->reloc();
455 }
wdenka042ac82002-09-12 22:36:57 +0000456 }
457}
Peter Tyser9057cbf2009-09-21 11:20:36 -0500458#endif
wdenka042ac82002-09-12 22:36:57 +0000459
wdenkc08f1582003-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 Schocher51ee5912011-10-12 01:18:05 +0000467unsigned long post_time_ms(unsigned long base)
wdenkc08f1582003-04-27 22:52:51 +0000468{
Tom Rini210ebce2017-03-14 11:08:10 -0400469#if defined(CONFIG_PPC) || defined(CONFIG_ARM)
Christian Rieschbb968ec2011-12-09 16:54:02 +0100470 return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000471 - base;
wdenkc08f1582003-04-27 22:52:51 +0000472#else
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100473#warning "Not implemented yet"
wdenkc08f1582003-04-27 22:52:51 +0000474 return 0; /* Not implemented yet */
475#endif
476}