blob: 696a60f70a7146a021ba95c59b724b9fe3746c6e [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>
Simon Glass9bc15642020-02-03 07:36:16 -07009#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020010#include <stdio_dev.h>
Simon Glass495a5dc2019-11-14 12:57:30 -070011#include <time.h>
wdenka042ac82002-09-12 22:36:57 +000012#include <watchdog.h>
Christian Rieschbb968ec2011-12-09 16:54:02 +010013#include <div64.h>
wdenka042ac82002-09-12 22:36:57 +000014#include <post.h>
15
Mike Frysinger2073edd2011-05-10 07:01:21 +000016#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
17#include <asm/gpio.h>
18#endif
19
Wolfgang Denk6405a152006-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 Schocher51ee5912011-10-12 01:18:05 +000026int post_init_f(void)
wdenkc08f1582003-04-27 22:52:51 +000027{
wdenkc08f1582003-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 Denkf7a49f12011-10-29 09:42:22 +000034 if (test->init_f && test->init_f())
wdenkc08f1582003-04-27 22:52:51 +000035 res = -1;
wdenkc08f1582003-04-27 22:52:51 +000036 }
wdenk57b2d802003-06-27 21:31:46 +000037
wdenkc08f1582003-04-27 22:52:51 +000038 gd->post_init_f_time = post_time_ms(0);
39 if (!gd->post_init_f_time)
Heiko Schocher51ee5912011-10-12 01:18:05 +000040 printf("%s: post_time_ms not implemented\n", __FILE__);
wdenkc08f1582003-04-27 22:52:51 +000041
42 return res;
43}
44
Stefan Roesef0a15c52009-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 Hofstee4e5f9e62014-10-08 22:57:25 +020053__weak int post_hotkeys_pressed(void)
Stefan Roesef0a15c52009-12-03 06:24:30 +010054{
Mike Frysinger2073edd2011-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 Roesef0a15c52009-12-03 06:24:30 +010072 return 0; /* No hotkeys supported */
73}
Stefan Roesef0a15c52009-12-03 06:24:30 +010074
Heiko Schocher51ee5912011-10-12 01:18:05 +000075void post_bootmode_init(void)
wdenka042ac82002-09-12 22:36:57 +000076{
Heiko Schocher51ee5912011-10-12 01:18:05 +000077 int bootmode = post_bootmode_get(0);
wdenk874ac262003-07-24 23:38:38 +000078 int newword;
wdenk9c53f402003-10-15 23:53:47 +000079
Heiko Schocher51ee5912011-10-12 01:18:05 +000080 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST))
wdenk874ac262003-07-24 23:38:38 +000081 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
Heiko Schocher51ee5912011-10-12 01:18:05 +000082 else if (bootmode == 0)
wdenk874ac262003-07-24 23:38:38 +000083 newword = BOOTMODE_MAGIC | POST_POWERON;
Heiko Schocher51ee5912011-10-12 01:18:05 +000084 else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST)
wdenk874ac262003-07-24 23:38:38 +000085 newword = BOOTMODE_MAGIC | POST_NORMAL;
Heiko Schocher51ee5912011-10-12 01:18:05 +000086 else
wdenk874ac262003-07-24 23:38:38 +000087 /* Use old value */
Wolfgang Denkf7a49f12011-10-29 09:42:22 +000088 newword = post_word_load() & ~POST_COLDBOOT;
wdenk874ac262003-07-24 23:38:38 +000089
90 if (bootmode == 0)
wdenk874ac262003-07-24 23:38:38 +000091 /* We are booting after power-on */
92 newword |= POST_COLDBOOT;
wdenka042ac82002-09-12 22:36:57 +000093
Heiko Schocher51ee5912011-10-12 01:18:05 +000094 post_word_store(newword);
wdenk874ac262003-07-24 23:38:38 +000095
wdenk9dfa8d12002-12-08 09:53:23 +000096 /* Reset activity record */
97 gd->post_log_word = 0;
Valentin Longchampb9181732011-08-03 02:37:01 +000098 gd->post_log_res = 0;
wdenka042ac82002-09-12 22:36:57 +000099}
100
Heiko Schocher51ee5912011-10-12 01:18:05 +0000101int post_bootmode_get(unsigned int *last_test)
wdenka042ac82002-09-12 22:36:57 +0000102{
Heiko Schocher51ee5912011-10-12 01:18:05 +0000103 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000104 int bootmode;
105
Heiko Schocher51ee5912011-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
wdenk874ac262003-07-24 23:38:38 +0000109 bootmode = word & 0x7F;
wdenka042ac82002-09-12 22:36:57 +0000110
Heiko Schocher51ee5912011-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
wdenk9dfa8d12002-12-08 09:53:23 +0000117/* POST tests run before relocation only mark status bits .... */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000118static void post_log_mark_start(unsigned long testid)
wdenk9dfa8d12002-12-08 09:53:23 +0000119{
Valentin Longchampb9181732011-08-03 02:37:01 +0000120 gd->post_log_word |= testid;
wdenk9dfa8d12002-12-08 09:53:23 +0000121}
122
Heiko Schocher51ee5912011-10-12 01:18:05 +0000123static void post_log_mark_succ(unsigned long testid)
wdenk9dfa8d12002-12-08 09:53:23 +0000124{
Valentin Longchampb9181732011-08-03 02:37:01 +0000125 gd->post_log_res |= testid;
wdenk9dfa8d12002-12-08 09:53:23 +0000126}
127
128/* ... and the messages are output once we are relocated */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000129void post_output_backlog(void)
wdenk9dfa8d12002-12-08 09:53:23 +0000130{
wdenk9dfa8d12002-12-08 09:53:23 +0000131 int j;
132
133 for (j = 0; j < post_list_size; j++) {
Valentin Longchampb9181732011-08-03 02:37:01 +0000134 if (gd->post_log_word & (post_list[j].testid)) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000135 post_log("POST %s ", post_list[j].cmd);
Valentin Longchampb9181732011-08-03 02:37:01 +0000136 if (gd->post_log_res & post_list[j].testid)
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000137 post_log("PASSED\n");
wdenke97d3d92004-02-23 22:22:28 +0000138 else {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000139 post_log("FAILED\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000140 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
wdenke97d3d92004-02-23 22:22:28 +0000141 }
wdenk9dfa8d12002-12-08 09:53:23 +0000142 }
143 }
144}
145
Heiko Schocher51ee5912011-10-12 01:18:05 +0000146static void post_bootmode_test_on(unsigned int last_test)
wdenka042ac82002-09-12 22:36:57 +0000147{
Heiko Schocher51ee5912011-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 Schocher51ee5912011-10-12 01:18:05 +0000154 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000155}
156
Heiko Schocher51ee5912011-10-12 01:18:05 +0000157static void post_bootmode_test_off(void)
wdenka042ac82002-09-12 22:36:57 +0000158{
Heiko Schocher51ee5912011-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 Schocher51ee5912011-10-12 01:18:05 +0000163 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000164}
165
Valentin Longchampcfc88802011-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 Tikhonov6a068a12008-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 Frysinger83a687b2011-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 Glass64b723f2017-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 Denkf7a49f12011-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 Denkf7a49f12011-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 Schocher51ee5912011-10-12 01:18:05 +0000209 if (j == post_list_size)
Wolfgang Denkf7a49f12011-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 Longchampcfc88802011-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
wdenkca9bc762003-07-15 07:45:49 +0000228
Heiko Schocher51ee5912011-10-12 01:18:05 +0000229 for (j = 0; j < post_list_size; j++)
230 if (test_flags[j] & POST_POWERON)
wdenkca9bc762003-07-15 07:45:49 +0000231 test_flags[j] |= POST_SLOWTEST;
wdenka042ac82002-09-12 22:36:57 +0000232}
233
Jeroen Hofstee4e5f9e62014-10-08 22:57:25 +0200234__weak void show_post_progress(unsigned int test_num, int before, int result)
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200235{
236}
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200237
Heiko Schocher51ee5912011-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 Denkf7a49f12011-10-29 09:42:22 +0000243 WATCHDOG_RESET();
wdenka042ac82002-09-12 22:36:57 +0000244
245 if (!(flags & POST_REBOOT)) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000246 if ((test_flags & POST_REBOOT) &&
247 !(flags & POST_MANUAL)) {
248 post_bootmode_test_on(
Yuri Tikhonov6a068a12008-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
wdenk9dfa8d12002-12-08 09:53:23 +0000253 if (test_flags & POST_PREREL)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000254 post_log_mark_start(test->testid);
wdenk9dfa8d12002-12-08 09:53:23 +0000255 else
Heiko Schocher51ee5912011-10-12 01:18:05 +0000256 post_log("POST %s ", test->cmd);
wdenka042ac82002-09-12 22:36:57 +0000257 }
258
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200259 show_post_progress(i, POST_BEFORE, POST_FAILED);
260
wdenk9dfa8d12002-12-08 09:53:23 +0000261 if (test_flags & POST_PREREL) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000262 if ((*test->test)(flags) == 0) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000263 post_log_mark_succ(test->testid);
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200264 show_post_progress(i, POST_AFTER, POST_PASSED);
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000265 } else {
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200266 show_post_progress(i, POST_AFTER, POST_FAILED);
Yuri Tikhonovbc439b02008-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 }
wdenk9dfa8d12002-12-08 09:53:23 +0000272 } else {
James Kosine7deffc2011-07-14 08:15:06 +0000273 if ((*test->test)(flags) != 0) {
274 post_log("FAILED\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000275 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
James Kosine7deffc2011-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 }
wdenk9dfa8d12002-12-08 09:53:23 +0000285 }
wdenka042ac82002-09-12 22:36:57 +0000286
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000287 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL))
Heiko Schocher51ee5912011-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 Denkf7a49f12011-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 Schocher51ee5912011-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 Tikhonovbc439b02008-05-08 15:45:26 +0200306 if (gd->flags & GD_FLG_POSTSTOP)
307 return 0;
308
Heiko Schocher51ee5912011-10-12 01:18:05 +0000309 if (post_bootmode_get(&last) & POST_POWERTEST) {
Yuri Tikhonov6a068a12008-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 Schocher51ee5912011-10-12 01:18:05 +0000318 post_run_single(post_list + last,
wdenk2029f4d2002-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 Tikhonovbc439b02008-05-08 15:45:26 +0200323 if (gd->flags & GD_FLG_POSTSTOP)
324 break;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000325 post_run_single(post_list + i,
wdenk2029f4d2002-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 Tikhonovbc439b02008-05-08 15:45:26 +0200332 if (gd->flags & GD_FLG_POSTSTOP)
333 break;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000334 post_run_single(post_list + i,
wdenk2029f4d2002-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 Denkf7a49f12011-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 Laue00150532008-05-30 09:48:14 +0200348 WATCHDOG_RESET();
Heiko Schocher51ee5912011-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 Schocher51ee5912011-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 Schocher51ee5912011-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 Schocher51ee5912011-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 Denkf7a49f12011-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 Schocher51ee5912011-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 Denkf7a49f12011-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 Denkf7a49f12011-10-29 09:42:22 +0000388 if (i < post_list_size)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000389 return post_info_single(post_list + i, 1);
Wolfgang Denkf7a49f12011-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 Schocher51ee5912011-10-12 01:18:05 +0000395int post_log(char *format, ...)
wdenka042ac82002-09-12 22:36:57 +0000396{
397 va_list args;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200398 char printbuffer[CONFIG_SYS_PBSIZE];
wdenka042ac82002-09-12 22:36:57 +0000399
Wolfgang Denkf7a49f12011-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 Denkbedfa0a2011-10-29 09:42:23 +0000405 vsprintf(printbuffer, format, args);
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000406 va_end(args);
wdenka042ac82002-09-12 22:36:57 +0000407
408 /* Send to the stdout file */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000409 puts(printbuffer);
wdenka042ac82002-09-12 22:36:57 +0000410
411 return 0;
412}
413
Wolfgang Denkd0813e52010-10-28 20:00:11 +0200414#ifdef CONFIG_NEEDS_MANUAL_RELOC
Heiko Schocher51ee5912011-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 Denkf7a49f12011-10-29 09:42:22 +0000427 addr = (ulong)(test->name) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000428 test->name = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000429 }
430
431 if (test->cmd) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000432 addr = (ulong)(test->cmd) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000433 test->cmd = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000434 }
435
436 if (test->desc) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000437 addr = (ulong)(test->desc) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000438 test->desc = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000439 }
440
441 if (test->test) {
Wolfgang Denkf7a49f12011-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 }
wdenkc08f1582003-04-27 22:52:51 +0000445
446 if (test->init_f) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000447 addr = (ulong)(test->init_f) + gd->reloc_off;
wdenkc08f1582003-04-27 22:52:51 +0000448 test->init_f = (int (*)(void)) addr;
449 }
450
451 if (test->reloc) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000452 addr = (ulong)(test->reloc) + gd->reloc_off;
wdenkc08f1582003-04-27 22:52:51 +0000453 test->reloc = (void (*)(void)) addr;
wdenk57b2d802003-06-27 21:31:46 +0000454
wdenkc08f1582003-04-27 22:52:51 +0000455 test->reloc();
456 }
wdenka042ac82002-09-12 22:36:57 +0000457 }
458}
Peter Tyser9057cbf2009-09-21 11:20:36 -0500459#endif
wdenka042ac82002-09-12 22:36:57 +0000460
wdenkc08f1582003-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 Schocher51ee5912011-10-12 01:18:05 +0000468unsigned long post_time_ms(unsigned long base)
wdenkc08f1582003-04-27 22:52:51 +0000469{
Tom Rini210ebce2017-03-14 11:08:10 -0400470#if defined(CONFIG_PPC) || defined(CONFIG_ARM)
Christian Rieschbb968ec2011-12-09 16:54:02 +0100471 return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000472 - base;
wdenkc08f1582003-04-27 22:52:51 +0000473#else
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100474#warning "Not implemented yet"
wdenkc08f1582003-04-27 22:52:51 +0000475 return 0; /* Not implemented yet */
476#endif
477}