wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 25 | #include <stdio_dev.h> |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 26 | #include <watchdog.h> |
| 27 | #include <post.h> |
| 28 | |
Mike Frysinger | 2073edd | 2011-05-10 07:01:21 +0000 | [diff] [blame] | 29 | #ifdef CONFIG_SYS_POST_HOTKEYS_GPIO |
| 30 | #include <asm/gpio.h> |
| 31 | #endif |
| 32 | |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 33 | #ifdef CONFIG_LOGBUFFER |
| 34 | #include <logbuff.h> |
| 35 | #endif |
| 36 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 37 | DECLARE_GLOBAL_DATA_PTR; |
| 38 | |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 39 | #define POST_MAX_NUMBER 32 |
| 40 | |
| 41 | #define BOOTMODE_MAGIC 0xDEAD0000 |
| 42 | |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 43 | int post_init_f (void) |
| 44 | { |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 45 | int res = 0; |
| 46 | unsigned int i; |
| 47 | |
| 48 | for (i = 0; i < post_list_size; i++) { |
| 49 | struct post_test *test = post_list + i; |
| 50 | |
| 51 | if (test->init_f && test->init_f()) { |
| 52 | res = -1; |
| 53 | } |
| 54 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 55 | |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 56 | gd->post_init_f_time = post_time_ms(0); |
| 57 | if (!gd->post_init_f_time) |
| 58 | { |
| 59 | printf("post/post.c: post_time_ms seems not to be implemented\n"); |
| 60 | } |
| 61 | |
| 62 | return res; |
| 63 | } |
| 64 | |
Stefan Roese | f0a15c5 | 2009-12-03 06:24:30 +0100 | [diff] [blame] | 65 | /* |
| 66 | * Supply a default implementation for post_hotkeys_pressed() for boards |
| 67 | * without hotkey support. We always return 0 here, so that the |
| 68 | * long-running tests won't be started. |
| 69 | * |
| 70 | * Boards with hotkey support can override this weak default function |
| 71 | * by defining one in their board specific code. |
| 72 | */ |
| 73 | int __post_hotkeys_pressed(void) |
| 74 | { |
Mike Frysinger | 2073edd | 2011-05-10 07:01:21 +0000 | [diff] [blame] | 75 | #ifdef CONFIG_SYS_POST_HOTKEYS_GPIO |
| 76 | int ret; |
| 77 | unsigned gpio = CONFIG_SYS_POST_HOTKEYS_GPIO; |
| 78 | |
| 79 | ret = gpio_request(gpio, "hotkeys"); |
| 80 | if (ret) { |
| 81 | printf("POST: gpio hotkey request failed\n"); |
| 82 | return 0; |
| 83 | } |
| 84 | |
| 85 | gpio_direction_input(gpio); |
| 86 | ret = gpio_get_value(gpio); |
| 87 | gpio_free(gpio); |
| 88 | |
| 89 | return ret; |
| 90 | #endif |
| 91 | |
Stefan Roese | f0a15c5 | 2009-12-03 06:24:30 +0100 | [diff] [blame] | 92 | return 0; /* No hotkeys supported */ |
| 93 | } |
| 94 | int post_hotkeys_pressed(void) |
| 95 | __attribute__((weak, alias("__post_hotkeys_pressed"))); |
| 96 | |
| 97 | |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 98 | void post_bootmode_init (void) |
| 99 | { |
| 100 | int bootmode = post_bootmode_get (0); |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 101 | int newword; |
wdenk | 9c53f40 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 102 | |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 103 | if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST)) { |
| 104 | newword = BOOTMODE_MAGIC | POST_SLOWTEST; |
wdenk | ca9bc76 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 105 | } else if (bootmode == 0) { |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 106 | newword = BOOTMODE_MAGIC | POST_POWERON; |
wdenk | ca9bc76 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 107 | } else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST) { |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 108 | newword = BOOTMODE_MAGIC | POST_NORMAL; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 109 | } else { |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 110 | /* Use old value */ |
| 111 | newword = post_word_load () & ~POST_COLDBOOT; |
| 112 | } |
| 113 | |
| 114 | if (bootmode == 0) |
| 115 | { |
| 116 | /* We are booting after power-on */ |
| 117 | newword |= POST_COLDBOOT; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 118 | } |
| 119 | |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 120 | post_word_store (newword); |
| 121 | |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 122 | /* Reset activity record */ |
| 123 | gd->post_log_word = 0; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | int post_bootmode_get (unsigned int *last_test) |
| 127 | { |
| 128 | unsigned long word = post_word_load (); |
| 129 | int bootmode; |
| 130 | |
| 131 | if ((word & 0xFFFF0000) != BOOTMODE_MAGIC) { |
| 132 | return 0; |
| 133 | } |
| 134 | |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 135 | bootmode = word & 0x7F; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 136 | |
| 137 | if (last_test && (bootmode & POST_POWERTEST)) { |
| 138 | *last_test = (word >> 8) & 0xFF; |
| 139 | } |
| 140 | |
| 141 | return bootmode; |
| 142 | } |
| 143 | |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 144 | /* POST tests run before relocation only mark status bits .... */ |
| 145 | static void post_log_mark_start ( unsigned long testid ) |
| 146 | { |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 147 | gd->post_log_word |= (testid)<<16; |
| 148 | } |
| 149 | |
| 150 | static void post_log_mark_succ ( unsigned long testid ) |
| 151 | { |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 152 | gd->post_log_word |= testid; |
| 153 | } |
| 154 | |
| 155 | /* ... and the messages are output once we are relocated */ |
| 156 | void post_output_backlog ( void ) |
| 157 | { |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 158 | int j; |
| 159 | |
| 160 | for (j = 0; j < post_list_size; j++) { |
| 161 | if (gd->post_log_word & (post_list[j].testid<<16)) { |
| 162 | post_log ("POST %s ", post_list[j].cmd); |
| 163 | if (gd->post_log_word & post_list[j].testid) |
| 164 | post_log ("PASSED\n"); |
wdenk | e97d3d9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 165 | else { |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 166 | post_log ("FAILED\n"); |
Heiko Schocher | 8a8ec53 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 167 | show_boot_progress (-31); |
wdenk | e97d3d9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 168 | } |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 173 | static void post_bootmode_test_on (unsigned int last_test) |
| 174 | { |
| 175 | unsigned long word = post_word_load (); |
| 176 | |
| 177 | word |= POST_POWERTEST; |
| 178 | |
| 179 | word |= (last_test & 0xFF) << 8; |
| 180 | |
| 181 | post_word_store (word); |
| 182 | } |
| 183 | |
| 184 | static void post_bootmode_test_off (void) |
| 185 | { |
| 186 | unsigned long word = post_word_load (); |
| 187 | |
| 188 | word &= ~POST_POWERTEST; |
| 189 | |
| 190 | post_word_store (word); |
| 191 | } |
| 192 | |
| 193 | static void post_get_flags (int *test_flags) |
| 194 | { |
Yuri Tikhonov | 6a068a1 | 2008-02-04 14:11:03 +0100 | [diff] [blame] | 195 | int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST, |
| 196 | POST_CRITICAL }; |
| 197 | char *var[] = { "post_poweron", "post_normal", "post_slowtest", |
| 198 | "post_critical" }; |
Mike Frysinger | 83a687b | 2011-05-10 07:28:35 +0000 | [diff] [blame] | 199 | int varnum = ARRAY_SIZE(var); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 200 | char list[128]; /* long enough for POST list */ |
| 201 | char *name; |
| 202 | char *s; |
| 203 | int last; |
| 204 | int i, j; |
| 205 | |
| 206 | for (j = 0; j < post_list_size; j++) { |
| 207 | test_flags[j] = post_list[j].flags; |
| 208 | } |
| 209 | |
| 210 | for (i = 0; i < varnum; i++) { |
Wolfgang Denk | 76af278 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 211 | if (getenv_f(var[i], list, sizeof (list)) <= 0) |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 212 | continue; |
| 213 | |
| 214 | for (j = 0; j < post_list_size; j++) { |
| 215 | test_flags[j] &= ~flag[i]; |
| 216 | } |
| 217 | |
| 218 | last = 0; |
| 219 | name = list; |
| 220 | while (!last) { |
| 221 | while (*name && *name == ' ') |
| 222 | name++; |
| 223 | if (*name == 0) |
| 224 | break; |
| 225 | s = name + 1; |
| 226 | while (*s && *s != ' ') |
| 227 | s++; |
| 228 | if (*s == 0) |
| 229 | last = 1; |
| 230 | else |
| 231 | *s = 0; |
| 232 | |
| 233 | for (j = 0; j < post_list_size; j++) { |
| 234 | if (strcmp (post_list[j].cmd, name) == 0) { |
| 235 | test_flags[j] |= flag[i]; |
| 236 | break; |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | if (j == post_list_size) { |
| 241 | printf ("No such test: %s\n", name); |
| 242 | } |
| 243 | |
| 244 | name = s + 1; |
| 245 | } |
| 246 | } |
wdenk | ca9bc76 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 247 | |
| 248 | for (j = 0; j < post_list_size; j++) { |
| 249 | if (test_flags[j] & POST_POWERON) { |
| 250 | test_flags[j] |= POST_SLOWTEST; |
| 251 | } |
| 252 | } |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Michael Zaidman | e3ac2b9 | 2010-03-01 11:47:36 +0200 | [diff] [blame] | 255 | void __show_post_progress (unsigned int test_num, int before, int result) |
| 256 | { |
| 257 | } |
| 258 | void show_post_progress (unsigned int, int, int) |
| 259 | __attribute__((weak, alias("__show_post_progress"))); |
| 260 | |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 261 | static int post_run_single (struct post_test *test, |
| 262 | int test_flags, int flags, unsigned int i) |
| 263 | { |
| 264 | if ((flags & test_flags & POST_ALWAYS) && |
| 265 | (flags & test_flags & POST_MEM)) { |
| 266 | WATCHDOG_RESET (); |
| 267 | |
| 268 | if (!(flags & POST_REBOOT)) { |
| 269 | if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) { |
Yuri Tikhonov | 6a068a1 | 2008-02-04 14:11:03 +0100 | [diff] [blame] | 270 | post_bootmode_test_on ( |
| 271 | (gd->flags & GD_FLG_POSTFAIL) ? |
| 272 | POST_FAIL_SAVE | i : i); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 273 | } |
| 274 | |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 275 | if (test_flags & POST_PREREL) |
| 276 | post_log_mark_start ( test->testid ); |
| 277 | else |
Michael Zaidman | e3ac2b9 | 2010-03-01 11:47:36 +0200 | [diff] [blame] | 278 | post_log ("POST %s ", test->cmd); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 279 | } |
| 280 | |
Michael Zaidman | e3ac2b9 | 2010-03-01 11:47:36 +0200 | [diff] [blame] | 281 | show_post_progress(i, POST_BEFORE, POST_FAILED); |
| 282 | |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 283 | if (test_flags & POST_PREREL) { |
Michael Zaidman | e3ac2b9 | 2010-03-01 11:47:36 +0200 | [diff] [blame] | 284 | if ((*test->test) (flags) == 0) { |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 285 | post_log_mark_succ ( test->testid ); |
Michael Zaidman | e3ac2b9 | 2010-03-01 11:47:36 +0200 | [diff] [blame] | 286 | show_post_progress(i, POST_AFTER, POST_PASSED); |
| 287 | } |
Yuri Tikhonov | bc439b0 | 2008-05-08 15:45:26 +0200 | [diff] [blame] | 288 | else { |
Michael Zaidman | e3ac2b9 | 2010-03-01 11:47:36 +0200 | [diff] [blame] | 289 | show_post_progress(i, POST_AFTER, POST_FAILED); |
Yuri Tikhonov | bc439b0 | 2008-05-08 15:45:26 +0200 | [diff] [blame] | 290 | if (test_flags & POST_CRITICAL) |
| 291 | gd->flags |= GD_FLG_POSTFAIL; |
| 292 | if (test_flags & POST_STOP) |
| 293 | gd->flags |= GD_FLG_POSTSTOP; |
| 294 | } |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 295 | } else { |
James Kosin | e7deffc | 2011-07-14 08:15:06 +0000 | [diff] [blame] | 296 | if ((*test->test)(flags) != 0) { |
| 297 | post_log("FAILED\n"); |
| 298 | show_boot_progress(-32); |
| 299 | show_post_progress(i, POST_AFTER, POST_FAILED); |
| 300 | if (test_flags & POST_CRITICAL) |
| 301 | gd->flags |= GD_FLG_POSTFAIL; |
| 302 | if (test_flags & POST_STOP) |
| 303 | gd->flags |= GD_FLG_POSTSTOP; |
| 304 | } else { |
| 305 | post_log("PASSED\n"); |
| 306 | show_post_progress(i, POST_AFTER, POST_PASSED); |
| 307 | } |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 308 | } |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 309 | |
| 310 | if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) { |
| 311 | post_bootmode_test_off (); |
| 312 | } |
| 313 | |
| 314 | return 0; |
| 315 | } else { |
| 316 | return -1; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | int post_run (char *name, int flags) |
| 321 | { |
| 322 | unsigned int i; |
| 323 | int test_flags[POST_MAX_NUMBER]; |
| 324 | |
| 325 | post_get_flags (test_flags); |
| 326 | |
| 327 | if (name == NULL) { |
| 328 | unsigned int last; |
| 329 | |
Yuri Tikhonov | bc439b0 | 2008-05-08 15:45:26 +0200 | [diff] [blame] | 330 | if (gd->flags & GD_FLG_POSTSTOP) |
| 331 | return 0; |
| 332 | |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 333 | if (post_bootmode_get (&last) & POST_POWERTEST) { |
Yuri Tikhonov | 6a068a1 | 2008-02-04 14:11:03 +0100 | [diff] [blame] | 334 | if (last & POST_FAIL_SAVE) { |
| 335 | last &= ~POST_FAIL_SAVE; |
| 336 | gd->flags |= GD_FLG_POSTFAIL; |
| 337 | } |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 338 | if (last < post_list_size && |
| 339 | (flags & test_flags[last] & POST_ALWAYS) && |
| 340 | (flags & test_flags[last] & POST_MEM)) { |
| 341 | |
wdenk | 2029f4d | 2002-11-21 23:11:29 +0000 | [diff] [blame] | 342 | post_run_single (post_list + last, |
| 343 | test_flags[last], |
| 344 | flags | POST_REBOOT, last); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 345 | |
| 346 | for (i = last + 1; i < post_list_size; i++) { |
Yuri Tikhonov | bc439b0 | 2008-05-08 15:45:26 +0200 | [diff] [blame] | 347 | if (gd->flags & GD_FLG_POSTSTOP) |
| 348 | break; |
wdenk | 2029f4d | 2002-11-21 23:11:29 +0000 | [diff] [blame] | 349 | post_run_single (post_list + i, |
| 350 | test_flags[i], |
| 351 | flags, i); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 352 | } |
| 353 | } |
| 354 | } else { |
| 355 | for (i = 0; i < post_list_size; i++) { |
Yuri Tikhonov | bc439b0 | 2008-05-08 15:45:26 +0200 | [diff] [blame] | 356 | if (gd->flags & GD_FLG_POSTSTOP) |
| 357 | break; |
wdenk | 2029f4d | 2002-11-21 23:11:29 +0000 | [diff] [blame] | 358 | post_run_single (post_list + i, |
| 359 | test_flags[i], |
| 360 | flags, i); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
| 364 | return 0; |
| 365 | } else { |
| 366 | for (i = 0; i < post_list_size; i++) { |
| 367 | if (strcmp (post_list[i].cmd, name) == 0) |
| 368 | break; |
| 369 | } |
| 370 | |
| 371 | if (i < post_list_size) { |
Sascha Laue | 0015053 | 2008-05-30 09:48:14 +0200 | [diff] [blame] | 372 | WATCHDOG_RESET(); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 373 | return post_run_single (post_list + i, |
| 374 | test_flags[i], |
| 375 | flags, i); |
| 376 | } else { |
| 377 | return -1; |
| 378 | } |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | static int post_info_single (struct post_test *test, int full) |
| 383 | { |
| 384 | if (test->flags & POST_MANUAL) { |
| 385 | if (full) |
| 386 | printf ("%s - %s\n" |
| 387 | " %s\n", test->cmd, test->name, test->desc); |
| 388 | else |
| 389 | printf (" %-15s - %s\n", test->cmd, test->name); |
| 390 | |
| 391 | return 0; |
| 392 | } else { |
| 393 | return -1; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | int post_info (char *name) |
| 398 | { |
| 399 | unsigned int i; |
| 400 | |
| 401 | if (name == NULL) { |
| 402 | for (i = 0; i < post_list_size; i++) { |
| 403 | post_info_single (post_list + i, 0); |
| 404 | } |
| 405 | |
| 406 | return 0; |
| 407 | } else { |
| 408 | for (i = 0; i < post_list_size; i++) { |
| 409 | if (strcmp (post_list[i].cmd, name) == 0) |
| 410 | break; |
| 411 | } |
| 412 | |
| 413 | if (i < post_list_size) { |
| 414 | return post_info_single (post_list + i, 1); |
| 415 | } else { |
| 416 | return -1; |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | int post_log (char *format, ...) |
| 422 | { |
| 423 | va_list args; |
| 424 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 425 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 426 | |
| 427 | va_start (args, format); |
| 428 | |
| 429 | /* For this to work, printbuffer must be larger than |
| 430 | * anything we ever want to print. |
| 431 | */ |
| 432 | i = vsprintf (printbuffer, format, args); |
| 433 | va_end (args); |
| 434 | |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 435 | #ifdef CONFIG_LOGBUFFER |
wdenk | 9dfa8d1 | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 436 | /* Send to the logbuffer */ |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 437 | logbuff_log (printbuffer); |
| 438 | #else |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 439 | /* Send to the stdout file */ |
| 440 | puts (printbuffer); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 441 | #endif |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 442 | |
| 443 | return 0; |
| 444 | } |
| 445 | |
Wolfgang Denk | d0813e5 | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 446 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 447 | void post_reloc (void) |
| 448 | { |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 449 | unsigned int i; |
| 450 | |
| 451 | /* |
| 452 | * We have to relocate the test table manually |
| 453 | */ |
| 454 | for (i = 0; i < post_list_size; i++) { |
| 455 | ulong addr; |
| 456 | struct post_test *test = post_list + i; |
| 457 | |
| 458 | if (test->name) { |
| 459 | addr = (ulong) (test->name) + gd->reloc_off; |
| 460 | test->name = (char *) addr; |
| 461 | } |
| 462 | |
| 463 | if (test->cmd) { |
| 464 | addr = (ulong) (test->cmd) + gd->reloc_off; |
| 465 | test->cmd = (char *) addr; |
| 466 | } |
| 467 | |
| 468 | if (test->desc) { |
| 469 | addr = (ulong) (test->desc) + gd->reloc_off; |
| 470 | test->desc = (char *) addr; |
| 471 | } |
| 472 | |
| 473 | if (test->test) { |
| 474 | addr = (ulong) (test->test) + gd->reloc_off; |
| 475 | test->test = (int (*)(int flags)) addr; |
| 476 | } |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 477 | |
| 478 | if (test->init_f) { |
| 479 | addr = (ulong) (test->init_f) + gd->reloc_off; |
| 480 | test->init_f = (int (*)(void)) addr; |
| 481 | } |
| 482 | |
| 483 | if (test->reloc) { |
| 484 | addr = (ulong) (test->reloc) + gd->reloc_off; |
| 485 | test->reloc = (void (*)(void)) addr; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 486 | |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 487 | test->reloc(); |
| 488 | } |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 489 | } |
| 490 | } |
Peter Tyser | 9057cbf | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 491 | #endif |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 492 | |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 493 | |
| 494 | /* |
| 495 | * Some tests (e.g. SYSMON) need the time when post_init_f started, |
| 496 | * but we cannot use get_timer() at this point. |
| 497 | * |
| 498 | * On PowerPC we implement it using the timebase register. |
| 499 | */ |
| 500 | unsigned long post_time_ms (unsigned long base) |
| 501 | { |
| 502 | #ifdef CONFIG_PPC |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 503 | return (unsigned long)(get_ticks () / (get_tbclk () / CONFIG_SYS_HZ)) - base; |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 504 | #else |
Wolfgang Denk | b38e0df | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 505 | #warning "Not implemented yet" |
wdenk | c08f158 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 506 | return 0; /* Not implemented yet */ |
| 507 | #endif |
| 508 | } |