blob: 946d9094d451fab9116fbc4d93061988fd985273 [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
Tom Rini3dd5d4a2022-12-04 10:14:17 -050019#ifdef CFG_SYS_POST_HOTKEYS_GPIO
Mike Frysinger2073edd2011-05-10 07:01:21 +000020#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{
Tom Rini3dd5d4a2022-12-04 10:14:17 -050058#ifdef CFG_SYS_POST_HOTKEYS_GPIO
Mike Frysinger2073edd2011-05-10 07:01:21 +000059 int ret;
Tom Rini3dd5d4a2022-12-04 10:14:17 -050060 unsigned gpio = CFG_SYS_POST_HOTKEYS_GPIO;
Mike Frysinger2073edd2011-05-10 07:01:21 +000061
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
Tom Rini8eaa3c72022-11-19 18:45:44 -0500171#ifndef CFG_POST_SKIP_ENV_FLAGS
Valentin Longchampcfc88802011-08-03 02:37:02 +0000172static 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
Tom Rini8eaa3c72022-11-19 18:45:44 -0500230#ifndef CFG_POST_SKIP_ENV_FLAGS
Valentin Longchampcfc88802011-08-03 02:37:02 +0000231 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
wdenkc08f1582003-04-27 22:52:51 +0000419/*
420 * Some tests (e.g. SYSMON) need the time when post_init_f started,
421 * but we cannot use get_timer() at this point.
422 *
423 * On PowerPC we implement it using the timebase register.
424 */
Heiko Schocher51ee5912011-10-12 01:18:05 +0000425unsigned long post_time_ms(unsigned long base)
wdenkc08f1582003-04-27 22:52:51 +0000426{
Tom Rini210ebce2017-03-14 11:08:10 -0400427#if defined(CONFIG_PPC) || defined(CONFIG_ARM)
Christian Rieschbb968ec2011-12-09 16:54:02 +0100428 return (unsigned long)lldiv(get_ticks(), get_tbclk() / CONFIG_SYS_HZ)
Heiko Schocher51ee5912011-10-12 01:18:05 +0000429 - base;
wdenkc08f1582003-04-27 22:52:51 +0000430#else
Wolfgang Denkb38e0df2007-03-06 18:08:43 +0100431#warning "Not implemented yet"
wdenkc08f1582003-04-27 22:52:51 +0000432 return 0; /* Not implemented yet */
433#endif
434}