blob: b81425d8cf81501ba206f5ab97c07e6f50996f4f [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 Glass1ea97892020-05-10 11:40:00 -06008#include <bootstage.h>
Simon Glassdb229612019-08-01 09:46:42 -06009#include <env.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070011#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020012#include <stdio_dev.h>
Simon Glass495a5dc2019-11-14 12:57:30 -070013#include <time.h>
wdenka042ac82002-09-12 22:36:57 +000014#include <watchdog.h>
Christian Rieschbb968ec2011-12-09 16:54:02 +010015#include <div64.h>
wdenka042ac82002-09-12 22:36:57 +000016#include <post.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
wdenka042ac82002-09-12 22:36:57 +000018
Mike Frysinger2073edd2011-05-10 07:01:21 +000019#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
20#include <asm/gpio.h>
21#endif
22
Wolfgang Denk6405a152006-03-31 18:32:53 +020023DECLARE_GLOBAL_DATA_PTR;
24
wdenka042ac82002-09-12 22:36:57 +000025#define POST_MAX_NUMBER 32
26
27#define BOOTMODE_MAGIC 0xDEAD0000
28
Heiko Schocher51ee5912011-10-12 01:18:05 +000029int post_init_f(void)
wdenkc08f1582003-04-27 22:52:51 +000030{
wdenkc08f1582003-04-27 22:52:51 +000031 int res = 0;
32 unsigned int i;
33
34 for (i = 0; i < post_list_size; i++) {
35 struct post_test *test = post_list + i;
36
Wolfgang Denkf7a49f12011-10-29 09:42:22 +000037 if (test->init_f && test->init_f())
wdenkc08f1582003-04-27 22:52:51 +000038 res = -1;
wdenkc08f1582003-04-27 22:52:51 +000039 }
wdenk57b2d802003-06-27 21:31:46 +000040
wdenkc08f1582003-04-27 22:52:51 +000041 gd->post_init_f_time = post_time_ms(0);
42 if (!gd->post_init_f_time)
Heiko Schocher51ee5912011-10-12 01:18:05 +000043 printf("%s: post_time_ms not implemented\n", __FILE__);
wdenkc08f1582003-04-27 22:52:51 +000044
45 return res;
46}
47
Stefan Roesef0a15c52009-12-03 06:24:30 +010048/*
49 * Supply a default implementation for post_hotkeys_pressed() for boards
50 * without hotkey support. We always return 0 here, so that the
51 * long-running tests won't be started.
52 *
53 * Boards with hotkey support can override this weak default function
54 * by defining one in their board specific code.
55 */
Jeroen Hofstee4e5f9e62014-10-08 22:57:25 +020056__weak int post_hotkeys_pressed(void)
Stefan Roesef0a15c52009-12-03 06:24:30 +010057{
Mike Frysinger2073edd2011-05-10 07:01:21 +000058#ifdef CONFIG_SYS_POST_HOTKEYS_GPIO
59 int ret;
60 unsigned gpio = CONFIG_SYS_POST_HOTKEYS_GPIO;
61
62 ret = gpio_request(gpio, "hotkeys");
63 if (ret) {
64 printf("POST: gpio hotkey request failed\n");
65 return 0;
66 }
67
68 gpio_direction_input(gpio);
69 ret = gpio_get_value(gpio);
70 gpio_free(gpio);
71
72 return ret;
73#endif
74
Stefan Roesef0a15c52009-12-03 06:24:30 +010075 return 0; /* No hotkeys supported */
76}
Stefan Roesef0a15c52009-12-03 06:24:30 +010077
Heiko Schocher51ee5912011-10-12 01:18:05 +000078void post_bootmode_init(void)
wdenka042ac82002-09-12 22:36:57 +000079{
Heiko Schocher51ee5912011-10-12 01:18:05 +000080 int bootmode = post_bootmode_get(0);
wdenk874ac262003-07-24 23:38:38 +000081 int newword;
wdenk9c53f402003-10-15 23:53:47 +000082
Heiko Schocher51ee5912011-10-12 01:18:05 +000083 if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST))
wdenk874ac262003-07-24 23:38:38 +000084 newword = BOOTMODE_MAGIC | POST_SLOWTEST;
Heiko Schocher51ee5912011-10-12 01:18:05 +000085 else if (bootmode == 0)
wdenk874ac262003-07-24 23:38:38 +000086 newword = BOOTMODE_MAGIC | POST_POWERON;
Heiko Schocher51ee5912011-10-12 01:18:05 +000087 else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST)
wdenk874ac262003-07-24 23:38:38 +000088 newword = BOOTMODE_MAGIC | POST_NORMAL;
Heiko Schocher51ee5912011-10-12 01:18:05 +000089 else
wdenk874ac262003-07-24 23:38:38 +000090 /* Use old value */
Wolfgang Denkf7a49f12011-10-29 09:42:22 +000091 newword = post_word_load() & ~POST_COLDBOOT;
wdenk874ac262003-07-24 23:38:38 +000092
93 if (bootmode == 0)
wdenk874ac262003-07-24 23:38:38 +000094 /* We are booting after power-on */
95 newword |= POST_COLDBOOT;
wdenka042ac82002-09-12 22:36:57 +000096
Heiko Schocher51ee5912011-10-12 01:18:05 +000097 post_word_store(newword);
wdenk874ac262003-07-24 23:38:38 +000098
wdenk9dfa8d12002-12-08 09:53:23 +000099 /* Reset activity record */
100 gd->post_log_word = 0;
Valentin Longchampb9181732011-08-03 02:37:01 +0000101 gd->post_log_res = 0;
wdenka042ac82002-09-12 22:36:57 +0000102}
103
Heiko Schocher51ee5912011-10-12 01:18:05 +0000104int post_bootmode_get(unsigned int *last_test)
wdenka042ac82002-09-12 22:36:57 +0000105{
Heiko Schocher51ee5912011-10-12 01:18:05 +0000106 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000107 int bootmode;
108
Heiko Schocher51ee5912011-10-12 01:18:05 +0000109 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC)
wdenka042ac82002-09-12 22:36:57 +0000110 return 0;
wdenka042ac82002-09-12 22:36:57 +0000111
wdenk874ac262003-07-24 23:38:38 +0000112 bootmode = word & 0x7F;
wdenka042ac82002-09-12 22:36:57 +0000113
Heiko Schocher51ee5912011-10-12 01:18:05 +0000114 if (last_test && (bootmode & POST_POWERTEST))
wdenka042ac82002-09-12 22:36:57 +0000115 *last_test = (word >> 8) & 0xFF;
wdenka042ac82002-09-12 22:36:57 +0000116
117 return bootmode;
118}
119
wdenk9dfa8d12002-12-08 09:53:23 +0000120/* POST tests run before relocation only mark status bits .... */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000121static void post_log_mark_start(unsigned long testid)
wdenk9dfa8d12002-12-08 09:53:23 +0000122{
Valentin Longchampb9181732011-08-03 02:37:01 +0000123 gd->post_log_word |= testid;
wdenk9dfa8d12002-12-08 09:53:23 +0000124}
125
Heiko Schocher51ee5912011-10-12 01:18:05 +0000126static void post_log_mark_succ(unsigned long testid)
wdenk9dfa8d12002-12-08 09:53:23 +0000127{
Valentin Longchampb9181732011-08-03 02:37:01 +0000128 gd->post_log_res |= testid;
wdenk9dfa8d12002-12-08 09:53:23 +0000129}
130
131/* ... and the messages are output once we are relocated */
Ovidiu Panaitdc8b6242020-11-28 10:43:10 +0200132int post_output_backlog(void)
wdenk9dfa8d12002-12-08 09:53:23 +0000133{
wdenk9dfa8d12002-12-08 09:53:23 +0000134 int j;
135
136 for (j = 0; j < post_list_size; j++) {
Valentin Longchampb9181732011-08-03 02:37:01 +0000137 if (gd->post_log_word & (post_list[j].testid)) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000138 post_log("POST %s ", post_list[j].cmd);
Valentin Longchampb9181732011-08-03 02:37:01 +0000139 if (gd->post_log_res & post_list[j].testid)
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000140 post_log("PASSED\n");
wdenke97d3d92004-02-23 22:22:28 +0000141 else {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000142 post_log("FAILED\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000143 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
wdenke97d3d92004-02-23 22:22:28 +0000144 }
wdenk9dfa8d12002-12-08 09:53:23 +0000145 }
146 }
Ovidiu Panaitdc8b6242020-11-28 10:43:10 +0200147
148 return 0;
wdenk9dfa8d12002-12-08 09:53:23 +0000149}
150
Heiko Schocher51ee5912011-10-12 01:18:05 +0000151static void post_bootmode_test_on(unsigned int last_test)
wdenka042ac82002-09-12 22:36:57 +0000152{
Heiko Schocher51ee5912011-10-12 01:18:05 +0000153 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000154
155 word |= POST_POWERTEST;
156
157 word |= (last_test & 0xFF) << 8;
158
Heiko Schocher51ee5912011-10-12 01:18:05 +0000159 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000160}
161
Heiko Schocher51ee5912011-10-12 01:18:05 +0000162static void post_bootmode_test_off(void)
wdenka042ac82002-09-12 22:36:57 +0000163{
Heiko Schocher51ee5912011-10-12 01:18:05 +0000164 unsigned long word = post_word_load();
wdenka042ac82002-09-12 22:36:57 +0000165
166 word &= ~POST_POWERTEST;
167
Heiko Schocher51ee5912011-10-12 01:18:05 +0000168 post_word_store(word);
wdenka042ac82002-09-12 22:36:57 +0000169}
170
Valentin Longchampcfc88802011-08-03 02:37:02 +0000171#ifndef CONFIG_POST_SKIP_ENV_FLAGS
172static void post_get_env_flags(int *test_flags)
wdenka042ac82002-09-12 22:36:57 +0000173{
Yuri Tikhonov6a068a12008-02-04 14:11:03 +0100174 int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST,
175 POST_CRITICAL };
176 char *var[] = { "post_poweron", "post_normal", "post_slowtest",
177 "post_critical" };
Mike Frysinger83a687b2011-05-10 07:28:35 +0000178 int varnum = ARRAY_SIZE(var);
wdenka042ac82002-09-12 22:36:57 +0000179 char list[128]; /* long enough for POST list */
180 char *name;
181 char *s;
182 int last;
183 int i, j;
184
wdenka042ac82002-09-12 22:36:57 +0000185 for (i = 0; i < varnum; i++) {
Simon Glass64b723f2017-08-03 12:22:12 -0600186 if (env_get_f(var[i], list, sizeof(list)) <= 0)
wdenka042ac82002-09-12 22:36:57 +0000187 continue;
188
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000189 for (j = 0; j < post_list_size; j++)
wdenka042ac82002-09-12 22:36:57 +0000190 test_flags[j] &= ~flag[i];
wdenka042ac82002-09-12 22:36:57 +0000191
192 last = 0;
193 name = list;
194 while (!last) {
Heinrich Schuchardtc5a0bc52020-08-03 22:12:13 +0200195 while (*name == ' ')
wdenka042ac82002-09-12 22:36:57 +0000196 name++;
197 if (*name == 0)
198 break;
199 s = name + 1;
200 while (*s && *s != ' ')
201 s++;
202 if (*s == 0)
203 last = 1;
204 else
205 *s = 0;
206
207 for (j = 0; j < post_list_size; j++) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000208 if (strcmp(post_list[j].cmd, name) == 0) {
wdenka042ac82002-09-12 22:36:57 +0000209 test_flags[j] |= flag[i];
210 break;
211 }
212 }
213
Heiko Schocher51ee5912011-10-12 01:18:05 +0000214 if (j == post_list_size)
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000215 printf("No such test: %s\n", name);
wdenka042ac82002-09-12 22:36:57 +0000216
217 name = s + 1;
218 }
219 }
Valentin Longchampcfc88802011-08-03 02:37:02 +0000220}
221#endif
222
223static void post_get_flags(int *test_flags)
224{
225 int j;
226
227 for (j = 0; j < post_list_size; j++)
228 test_flags[j] = post_list[j].flags;
229
230#ifndef CONFIG_POST_SKIP_ENV_FLAGS
231 post_get_env_flags(test_flags);
232#endif
wdenkca9bc762003-07-15 07:45:49 +0000233
Heiko Schocher51ee5912011-10-12 01:18:05 +0000234 for (j = 0; j < post_list_size; j++)
235 if (test_flags[j] & POST_POWERON)
wdenkca9bc762003-07-15 07:45:49 +0000236 test_flags[j] |= POST_SLOWTEST;
wdenka042ac82002-09-12 22:36:57 +0000237}
238
Jeroen Hofstee4e5f9e62014-10-08 22:57:25 +0200239__weak void show_post_progress(unsigned int test_num, int before, int result)
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200240{
241}
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200242
Heiko Schocher51ee5912011-10-12 01:18:05 +0000243static int post_run_single(struct post_test *test,
wdenka042ac82002-09-12 22:36:57 +0000244 int test_flags, int flags, unsigned int i)
245{
246 if ((flags & test_flags & POST_ALWAYS) &&
247 (flags & test_flags & POST_MEM)) {
Stefan Roese80877fa2022-09-02 14:10:46 +0200248 schedule();
wdenka042ac82002-09-12 22:36:57 +0000249
250 if (!(flags & POST_REBOOT)) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000251 if ((test_flags & POST_REBOOT) &&
252 !(flags & POST_MANUAL)) {
253 post_bootmode_test_on(
Yuri Tikhonov6a068a12008-02-04 14:11:03 +0100254 (gd->flags & GD_FLG_POSTFAIL) ?
255 POST_FAIL_SAVE | i : i);
wdenka042ac82002-09-12 22:36:57 +0000256 }
257
wdenk9dfa8d12002-12-08 09:53:23 +0000258 if (test_flags & POST_PREREL)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000259 post_log_mark_start(test->testid);
wdenk9dfa8d12002-12-08 09:53:23 +0000260 else
Heiko Schocher51ee5912011-10-12 01:18:05 +0000261 post_log("POST %s ", test->cmd);
wdenka042ac82002-09-12 22:36:57 +0000262 }
263
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200264 show_post_progress(i, POST_BEFORE, POST_FAILED);
265
wdenk9dfa8d12002-12-08 09:53:23 +0000266 if (test_flags & POST_PREREL) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000267 if ((*test->test)(flags) == 0) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000268 post_log_mark_succ(test->testid);
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200269 show_post_progress(i, POST_AFTER, POST_PASSED);
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000270 } else {
Michael Zaidmane3ac2b92010-03-01 11:47:36 +0200271 show_post_progress(i, POST_AFTER, POST_FAILED);
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200272 if (test_flags & POST_CRITICAL)
273 gd->flags |= GD_FLG_POSTFAIL;
274 if (test_flags & POST_STOP)
275 gd->flags |= GD_FLG_POSTSTOP;
276 }
wdenk9dfa8d12002-12-08 09:53:23 +0000277 } else {
James Kosine7deffc2011-07-14 08:15:06 +0000278 if ((*test->test)(flags) != 0) {
279 post_log("FAILED\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000280 bootstage_error(BOOTSTAGE_ID_POST_FAIL_R);
James Kosine7deffc2011-07-14 08:15:06 +0000281 show_post_progress(i, POST_AFTER, POST_FAILED);
282 if (test_flags & POST_CRITICAL)
283 gd->flags |= GD_FLG_POSTFAIL;
284 if (test_flags & POST_STOP)
285 gd->flags |= GD_FLG_POSTSTOP;
286 } else {
287 post_log("PASSED\n");
288 show_post_progress(i, POST_AFTER, POST_PASSED);
289 }
wdenk9dfa8d12002-12-08 09:53:23 +0000290 }
wdenka042ac82002-09-12 22:36:57 +0000291
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000292 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL))
Heiko Schocher51ee5912011-10-12 01:18:05 +0000293 post_bootmode_test_off();
wdenka042ac82002-09-12 22:36:57 +0000294
295 return 0;
296 } else {
297 return -1;
298 }
299}
300
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000301int post_run(char *name, int flags)
wdenka042ac82002-09-12 22:36:57 +0000302{
303 unsigned int i;
304 int test_flags[POST_MAX_NUMBER];
305
Heiko Schocher51ee5912011-10-12 01:18:05 +0000306 post_get_flags(test_flags);
wdenka042ac82002-09-12 22:36:57 +0000307
308 if (name == NULL) {
309 unsigned int last;
310
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200311 if (gd->flags & GD_FLG_POSTSTOP)
312 return 0;
313
Heiko Schocher51ee5912011-10-12 01:18:05 +0000314 if (post_bootmode_get(&last) & POST_POWERTEST) {
Yuri Tikhonov6a068a12008-02-04 14:11:03 +0100315 if (last & POST_FAIL_SAVE) {
316 last &= ~POST_FAIL_SAVE;
317 gd->flags |= GD_FLG_POSTFAIL;
318 }
wdenka042ac82002-09-12 22:36:57 +0000319 if (last < post_list_size &&
320 (flags & test_flags[last] & POST_ALWAYS) &&
321 (flags & test_flags[last] & POST_MEM)) {
322
Heiko Schocher51ee5912011-10-12 01:18:05 +0000323 post_run_single(post_list + last,
wdenk2029f4d2002-11-21 23:11:29 +0000324 test_flags[last],
325 flags | POST_REBOOT, last);
wdenka042ac82002-09-12 22:36:57 +0000326
327 for (i = last + 1; i < post_list_size; i++) {
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200328 if (gd->flags & GD_FLG_POSTSTOP)
329 break;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000330 post_run_single(post_list + i,
wdenk2029f4d2002-11-21 23:11:29 +0000331 test_flags[i],
332 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000333 }
334 }
335 } else {
336 for (i = 0; i < post_list_size; i++) {
Yuri Tikhonovbc439b02008-05-08 15:45:26 +0200337 if (gd->flags & GD_FLG_POSTSTOP)
338 break;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000339 post_run_single(post_list + i,
wdenk2029f4d2002-11-21 23:11:29 +0000340 test_flags[i],
341 flags, i);
wdenka042ac82002-09-12 22:36:57 +0000342 }
343 }
344
345 return 0;
346 } else {
347 for (i = 0; i < post_list_size; i++) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000348 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000349 break;
350 }
351
352 if (i < post_list_size) {
Stefan Roese80877fa2022-09-02 14:10:46 +0200353 schedule();
Heiko Schocher51ee5912011-10-12 01:18:05 +0000354 return post_run_single(post_list + i,
wdenka042ac82002-09-12 22:36:57 +0000355 test_flags[i],
356 flags, i);
357 } else {
358 return -1;
359 }
360 }
361}
362
Heiko Schocher51ee5912011-10-12 01:18:05 +0000363static int post_info_single(struct post_test *test, int full)
wdenka042ac82002-09-12 22:36:57 +0000364{
365 if (test->flags & POST_MANUAL) {
366 if (full)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000367 printf("%s - %s\n"
wdenka042ac82002-09-12 22:36:57 +0000368 " %s\n", test->cmd, test->name, test->desc);
369 else
Heiko Schocher51ee5912011-10-12 01:18:05 +0000370 printf(" %-15s - %s\n", test->cmd, test->name);
wdenka042ac82002-09-12 22:36:57 +0000371
372 return 0;
373 } else {
374 return -1;
375 }
376}
377
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000378int post_info(char *name)
wdenka042ac82002-09-12 22:36:57 +0000379{
380 unsigned int i;
381
382 if (name == NULL) {
Heiko Schocher51ee5912011-10-12 01:18:05 +0000383 for (i = 0; i < post_list_size; i++)
384 post_info_single(post_list + i, 0);
wdenka042ac82002-09-12 22:36:57 +0000385
386 return 0;
387 } else {
388 for (i = 0; i < post_list_size; i++) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000389 if (strcmp(post_list[i].cmd, name) == 0)
wdenka042ac82002-09-12 22:36:57 +0000390 break;
391 }
392
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000393 if (i < post_list_size)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000394 return post_info_single(post_list + i, 1);
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000395 else
wdenka042ac82002-09-12 22:36:57 +0000396 return -1;
wdenka042ac82002-09-12 22:36:57 +0000397 }
398}
399
Heiko Schocher51ee5912011-10-12 01:18:05 +0000400int post_log(char *format, ...)
wdenka042ac82002-09-12 22:36:57 +0000401{
402 va_list args;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200403 char printbuffer[CONFIG_SYS_PBSIZE];
wdenka042ac82002-09-12 22:36:57 +0000404
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000405 va_start(args, format);
wdenka042ac82002-09-12 22:36:57 +0000406
407 /* For this to work, printbuffer must be larger than
408 * anything we ever want to print.
409 */
Wolfgang Denkbedfa0a2011-10-29 09:42:23 +0000410 vsprintf(printbuffer, format, args);
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000411 va_end(args);
wdenka042ac82002-09-12 22:36:57 +0000412
413 /* Send to the stdout file */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000414 puts(printbuffer);
wdenka042ac82002-09-12 22:36:57 +0000415
416 return 0;
417}
418
Wolfgang Denkd0813e52010-10-28 20:00:11 +0200419#ifdef CONFIG_NEEDS_MANUAL_RELOC
Heiko Schocher51ee5912011-10-12 01:18:05 +0000420void post_reloc(void)
wdenka042ac82002-09-12 22:36:57 +0000421{
wdenka042ac82002-09-12 22:36:57 +0000422 unsigned int i;
423
424 /*
425 * We have to relocate the test table manually
426 */
427 for (i = 0; i < post_list_size; i++) {
428 ulong addr;
429 struct post_test *test = post_list + i;
430
431 if (test->name) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000432 addr = (ulong)(test->name) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000433 test->name = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000434 }
435
436 if (test->cmd) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000437 addr = (ulong)(test->cmd) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000438 test->cmd = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000439 }
440
441 if (test->desc) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000442 addr = (ulong)(test->desc) + gd->reloc_off;
Heiko Schocher51ee5912011-10-12 01:18:05 +0000443 test->desc = (char *)addr;
wdenka042ac82002-09-12 22:36:57 +0000444 }
445
446 if (test->test) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000447 addr = (ulong)(test->test) + gd->reloc_off;
wdenka042ac82002-09-12 22:36:57 +0000448 test->test = (int (*)(int flags)) addr;
449 }
wdenkc08f1582003-04-27 22:52:51 +0000450
451 if (test->init_f) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000452 addr = (ulong)(test->init_f) + gd->reloc_off;
wdenkc08f1582003-04-27 22:52:51 +0000453 test->init_f = (int (*)(void)) addr;
454 }
455
456 if (test->reloc) {
Wolfgang Denkf7a49f12011-10-29 09:42:22 +0000457 addr = (ulong)(test->reloc) + gd->reloc_off;
wdenkc08f1582003-04-27 22:52:51 +0000458 test->reloc = (void (*)(void)) addr;
wdenk57b2d802003-06-27 21:31:46 +0000459
wdenkc08f1582003-04-27 22:52:51 +0000460 test->reloc();
461 }
wdenka042ac82002-09-12 22:36:57 +0000462 }
463}
Peter Tyser9057cbf2009-09-21 11:20:36 -0500464#endif
wdenka042ac82002-09-12 22:36:57 +0000465
wdenkc08f1582003-04-27 22:52:51 +0000466
467/*
468 * Some tests (e.g. SYSMON) need the time when post_init_f started,
469 * but we cannot use get_timer() at this point.
470 *
471 * On PowerPC we implement it using the timebase register.
472 */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000473unsigned long post_time_ms(unsigned long base)
wdenkc08f1582003-04-27 22:52:51 +0000474{
Tom Rini210ebce2017-03-14 11:08:10 -0400475#if defined(CONFIG_PPC) || defined(CONFIG_ARM)
Christian Rieschbb968ec2011-12-09 16:54:02 +0100476 return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000477 - base;
wdenkc08f1582003-04-27 22:52:51 +0000478#else
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100479#warning "Not implemented yet"
wdenkc08f1582003-04-27 22:52:51 +0000480 return 0; /* Not implemented yet */
481#endif
482}