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 | 52cb4d4 | 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 | 9146d13 | 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 | d87080b | 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 | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 43 | int post_init_f (void) |
| 44 | { |
wdenk | 4532cb6 | 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 | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 55 | |
wdenk | 4532cb6 | 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 | 39ff7d5 | 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 | 9146d13 | 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 | 39ff7d5 | 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 | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 101 | int newword; |
wdenk | 42d1f03 | 2003-10-15 23:53:47 +0000 | [diff] [blame] | 102 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 103 | if (post_hotkeys_pressed() && !(bootmode & POST_POWERTEST)) { |
| 104 | newword = BOOTMODE_MAGIC | POST_SLOWTEST; |
wdenk | 6dff552 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 105 | } else if (bootmode == 0) { |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 106 | newword = BOOTMODE_MAGIC | POST_POWERON; |
wdenk | 6dff552 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 107 | } else if (bootmode == POST_POWERON || bootmode == POST_SLOWTEST) { |
wdenk | 27b207f | 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 | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 110 | /* Use old value */ |
| 111 | newword = post_word_load () & ~POST_COLDBOOT; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 112 | } |
| 113 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 114 | if (bootmode == 0) |
| 115 | { |
| 116 | /* We are booting after power-on */ |
| 117 | newword |= POST_COLDBOOT; |
| 118 | } |
| 119 | |
| 120 | post_word_store (newword); |
| 121 | |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 122 | /* Reset activity record */ |
| 123 | gd->post_log_word = 0; |
Valentin Longchamp | 7984395 | 2011-08-03 02:37:01 +0000 | [diff] [blame] | 124 | gd->post_log_res = 0; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | int post_bootmode_get (unsigned int *last_test) |
| 128 | { |
| 129 | unsigned long word = post_word_load (); |
| 130 | int bootmode; |
| 131 | |
| 132 | if ((word & 0xFFFF0000) != BOOTMODE_MAGIC) { |
| 133 | return 0; |
| 134 | } |
| 135 | |
wdenk | 27b207f | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 136 | bootmode = word & 0x7F; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 137 | |
| 138 | if (last_test && (bootmode & POST_POWERTEST)) { |
| 139 | *last_test = (word >> 8) & 0xFF; |
| 140 | } |
| 141 | |
| 142 | return bootmode; |
| 143 | } |
| 144 | |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 145 | /* POST tests run before relocation only mark status bits .... */ |
| 146 | static void post_log_mark_start ( unsigned long testid ) |
| 147 | { |
Valentin Longchamp | 7984395 | 2011-08-03 02:37:01 +0000 | [diff] [blame] | 148 | gd->post_log_word |= testid; |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static void post_log_mark_succ ( unsigned long testid ) |
| 152 | { |
Valentin Longchamp | 7984395 | 2011-08-03 02:37:01 +0000 | [diff] [blame] | 153 | gd->post_log_res |= testid; |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /* ... and the messages are output once we are relocated */ |
| 157 | void post_output_backlog ( void ) |
| 158 | { |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 159 | int j; |
| 160 | |
| 161 | for (j = 0; j < post_list_size; j++) { |
Valentin Longchamp | 7984395 | 2011-08-03 02:37:01 +0000 | [diff] [blame] | 162 | if (gd->post_log_word & (post_list[j].testid)) { |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 163 | post_log ("POST %s ", post_list[j].cmd); |
Valentin Longchamp | 7984395 | 2011-08-03 02:37:01 +0000 | [diff] [blame] | 164 | if (gd->post_log_res & post_list[j].testid) |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 165 | post_log ("PASSED\n"); |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 166 | else { |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 167 | post_log ("FAILED\n"); |
Heiko Schocher | fad6340 | 2007-07-13 09:54:17 +0200 | [diff] [blame] | 168 | show_boot_progress (-31); |
wdenk | 63e73c9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 169 | } |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 174 | static void post_bootmode_test_on (unsigned int last_test) |
| 175 | { |
| 176 | unsigned long word = post_word_load (); |
| 177 | |
| 178 | word |= POST_POWERTEST; |
| 179 | |
| 180 | word |= (last_test & 0xFF) << 8; |
| 181 | |
| 182 | post_word_store (word); |
| 183 | } |
| 184 | |
| 185 | static void post_bootmode_test_off (void) |
| 186 | { |
| 187 | unsigned long word = post_word_load (); |
| 188 | |
| 189 | word &= ~POST_POWERTEST; |
| 190 | |
| 191 | post_word_store (word); |
| 192 | } |
| 193 | |
Valentin Longchamp | 212a0ca | 2011-08-03 02:37:02 +0000 | [diff] [blame^] | 194 | #ifndef CONFIG_POST_SKIP_ENV_FLAGS |
| 195 | static void post_get_env_flags(int *test_flags) |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 196 | { |
Yuri Tikhonov | e262efe | 2008-02-04 14:11:03 +0100 | [diff] [blame] | 197 | int flag[] = { POST_POWERON, POST_NORMAL, POST_SLOWTEST, |
| 198 | POST_CRITICAL }; |
| 199 | char *var[] = { "post_poweron", "post_normal", "post_slowtest", |
| 200 | "post_critical" }; |
Mike Frysinger | d239781 | 2011-05-10 07:28:35 +0000 | [diff] [blame] | 201 | int varnum = ARRAY_SIZE(var); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 202 | char list[128]; /* long enough for POST list */ |
| 203 | char *name; |
| 204 | char *s; |
| 205 | int last; |
| 206 | int i, j; |
| 207 | |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 208 | for (i = 0; i < varnum; i++) { |
Wolfgang Denk | cdb7497 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 209 | if (getenv_f(var[i], list, sizeof (list)) <= 0) |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 210 | continue; |
| 211 | |
| 212 | for (j = 0; j < post_list_size; j++) { |
| 213 | test_flags[j] &= ~flag[i]; |
| 214 | } |
| 215 | |
| 216 | last = 0; |
| 217 | name = list; |
| 218 | while (!last) { |
| 219 | while (*name && *name == ' ') |
| 220 | name++; |
| 221 | if (*name == 0) |
| 222 | break; |
| 223 | s = name + 1; |
| 224 | while (*s && *s != ' ') |
| 225 | s++; |
| 226 | if (*s == 0) |
| 227 | last = 1; |
| 228 | else |
| 229 | *s = 0; |
| 230 | |
| 231 | for (j = 0; j < post_list_size; j++) { |
| 232 | if (strcmp (post_list[j].cmd, name) == 0) { |
| 233 | test_flags[j] |= flag[i]; |
| 234 | break; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | if (j == post_list_size) { |
| 239 | printf ("No such test: %s\n", name); |
| 240 | } |
| 241 | |
| 242 | name = s + 1; |
| 243 | } |
| 244 | } |
Valentin Longchamp | 212a0ca | 2011-08-03 02:37:02 +0000 | [diff] [blame^] | 245 | } |
| 246 | #endif |
| 247 | |
| 248 | static void post_get_flags(int *test_flags) |
| 249 | { |
| 250 | int j; |
| 251 | |
| 252 | for (j = 0; j < post_list_size; j++) |
| 253 | test_flags[j] = post_list[j].flags; |
| 254 | |
| 255 | #ifndef CONFIG_POST_SKIP_ENV_FLAGS |
| 256 | post_get_env_flags(test_flags); |
| 257 | #endif |
wdenk | 6dff552 | 2003-07-15 07:45:49 +0000 | [diff] [blame] | 258 | |
| 259 | for (j = 0; j < post_list_size; j++) { |
| 260 | if (test_flags[j] & POST_POWERON) { |
| 261 | test_flags[j] |= POST_SLOWTEST; |
| 262 | } |
| 263 | } |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Michael Zaidman | e070a56 | 2010-03-01 11:47:36 +0200 | [diff] [blame] | 266 | void __show_post_progress (unsigned int test_num, int before, int result) |
| 267 | { |
| 268 | } |
| 269 | void show_post_progress (unsigned int, int, int) |
| 270 | __attribute__((weak, alias("__show_post_progress"))); |
| 271 | |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 272 | static int post_run_single (struct post_test *test, |
| 273 | int test_flags, int flags, unsigned int i) |
| 274 | { |
| 275 | if ((flags & test_flags & POST_ALWAYS) && |
| 276 | (flags & test_flags & POST_MEM)) { |
| 277 | WATCHDOG_RESET (); |
| 278 | |
| 279 | if (!(flags & POST_REBOOT)) { |
| 280 | if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) { |
Yuri Tikhonov | e262efe | 2008-02-04 14:11:03 +0100 | [diff] [blame] | 281 | post_bootmode_test_on ( |
| 282 | (gd->flags & GD_FLG_POSTFAIL) ? |
| 283 | POST_FAIL_SAVE | i : i); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 284 | } |
| 285 | |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 286 | if (test_flags & POST_PREREL) |
| 287 | post_log_mark_start ( test->testid ); |
| 288 | else |
Michael Zaidman | e070a56 | 2010-03-01 11:47:36 +0200 | [diff] [blame] | 289 | post_log ("POST %s ", test->cmd); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Michael Zaidman | e070a56 | 2010-03-01 11:47:36 +0200 | [diff] [blame] | 292 | show_post_progress(i, POST_BEFORE, POST_FAILED); |
| 293 | |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 294 | if (test_flags & POST_PREREL) { |
Michael Zaidman | e070a56 | 2010-03-01 11:47:36 +0200 | [diff] [blame] | 295 | if ((*test->test) (flags) == 0) { |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 296 | post_log_mark_succ ( test->testid ); |
Michael Zaidman | e070a56 | 2010-03-01 11:47:36 +0200 | [diff] [blame] | 297 | show_post_progress(i, POST_AFTER, POST_PASSED); |
| 298 | } |
Yuri Tikhonov | 28a3850 | 2008-05-08 15:45:26 +0200 | [diff] [blame] | 299 | else { |
Michael Zaidman | e070a56 | 2010-03-01 11:47:36 +0200 | [diff] [blame] | 300 | show_post_progress(i, POST_AFTER, POST_FAILED); |
Yuri Tikhonov | 28a3850 | 2008-05-08 15:45:26 +0200 | [diff] [blame] | 301 | if (test_flags & POST_CRITICAL) |
| 302 | gd->flags |= GD_FLG_POSTFAIL; |
| 303 | if (test_flags & POST_STOP) |
| 304 | gd->flags |= GD_FLG_POSTSTOP; |
| 305 | } |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 306 | } else { |
James Kosin | 975afc3 | 2011-07-14 08:15:06 +0000 | [diff] [blame] | 307 | if ((*test->test)(flags) != 0) { |
| 308 | post_log("FAILED\n"); |
| 309 | show_boot_progress(-32); |
| 310 | show_post_progress(i, POST_AFTER, POST_FAILED); |
| 311 | if (test_flags & POST_CRITICAL) |
| 312 | gd->flags |= GD_FLG_POSTFAIL; |
| 313 | if (test_flags & POST_STOP) |
| 314 | gd->flags |= GD_FLG_POSTSTOP; |
| 315 | } else { |
| 316 | post_log("PASSED\n"); |
| 317 | show_post_progress(i, POST_AFTER, POST_PASSED); |
| 318 | } |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 319 | } |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 320 | |
| 321 | if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) { |
| 322 | post_bootmode_test_off (); |
| 323 | } |
| 324 | |
| 325 | return 0; |
| 326 | } else { |
| 327 | return -1; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | int post_run (char *name, int flags) |
| 332 | { |
| 333 | unsigned int i; |
| 334 | int test_flags[POST_MAX_NUMBER]; |
| 335 | |
| 336 | post_get_flags (test_flags); |
| 337 | |
| 338 | if (name == NULL) { |
| 339 | unsigned int last; |
| 340 | |
Yuri Tikhonov | 28a3850 | 2008-05-08 15:45:26 +0200 | [diff] [blame] | 341 | if (gd->flags & GD_FLG_POSTSTOP) |
| 342 | return 0; |
| 343 | |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 344 | if (post_bootmode_get (&last) & POST_POWERTEST) { |
Yuri Tikhonov | e262efe | 2008-02-04 14:11:03 +0100 | [diff] [blame] | 345 | if (last & POST_FAIL_SAVE) { |
| 346 | last &= ~POST_FAIL_SAVE; |
| 347 | gd->flags |= GD_FLG_POSTFAIL; |
| 348 | } |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 349 | if (last < post_list_size && |
| 350 | (flags & test_flags[last] & POST_ALWAYS) && |
| 351 | (flags & test_flags[last] & POST_MEM)) { |
| 352 | |
wdenk | ea909b7 | 2002-11-21 23:11:29 +0000 | [diff] [blame] | 353 | post_run_single (post_list + last, |
| 354 | test_flags[last], |
| 355 | flags | POST_REBOOT, last); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 356 | |
| 357 | for (i = last + 1; i < post_list_size; i++) { |
Yuri Tikhonov | 28a3850 | 2008-05-08 15:45:26 +0200 | [diff] [blame] | 358 | if (gd->flags & GD_FLG_POSTSTOP) |
| 359 | break; |
wdenk | ea909b7 | 2002-11-21 23:11:29 +0000 | [diff] [blame] | 360 | post_run_single (post_list + i, |
| 361 | test_flags[i], |
| 362 | flags, i); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | } else { |
| 366 | for (i = 0; i < post_list_size; i++) { |
Yuri Tikhonov | 28a3850 | 2008-05-08 15:45:26 +0200 | [diff] [blame] | 367 | if (gd->flags & GD_FLG_POSTSTOP) |
| 368 | break; |
wdenk | ea909b7 | 2002-11-21 23:11:29 +0000 | [diff] [blame] | 369 | post_run_single (post_list + i, |
| 370 | test_flags[i], |
| 371 | flags, i); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 372 | } |
| 373 | } |
| 374 | |
| 375 | return 0; |
| 376 | } else { |
| 377 | for (i = 0; i < post_list_size; i++) { |
| 378 | if (strcmp (post_list[i].cmd, name) == 0) |
| 379 | break; |
| 380 | } |
| 381 | |
| 382 | if (i < post_list_size) { |
Sascha Laue | 5744ddc | 2008-05-30 09:48:14 +0200 | [diff] [blame] | 383 | WATCHDOG_RESET(); |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 384 | return post_run_single (post_list + i, |
| 385 | test_flags[i], |
| 386 | flags, i); |
| 387 | } else { |
| 388 | return -1; |
| 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | static int post_info_single (struct post_test *test, int full) |
| 394 | { |
| 395 | if (test->flags & POST_MANUAL) { |
| 396 | if (full) |
| 397 | printf ("%s - %s\n" |
| 398 | " %s\n", test->cmd, test->name, test->desc); |
| 399 | else |
| 400 | printf (" %-15s - %s\n", test->cmd, test->name); |
| 401 | |
| 402 | return 0; |
| 403 | } else { |
| 404 | return -1; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | int post_info (char *name) |
| 409 | { |
| 410 | unsigned int i; |
| 411 | |
| 412 | if (name == NULL) { |
| 413 | for (i = 0; i < post_list_size; i++) { |
| 414 | post_info_single (post_list + i, 0); |
| 415 | } |
| 416 | |
| 417 | return 0; |
| 418 | } else { |
| 419 | for (i = 0; i < post_list_size; i++) { |
| 420 | if (strcmp (post_list[i].cmd, name) == 0) |
| 421 | break; |
| 422 | } |
| 423 | |
| 424 | if (i < post_list_size) { |
| 425 | return post_info_single (post_list + i, 1); |
| 426 | } else { |
| 427 | return -1; |
| 428 | } |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | int post_log (char *format, ...) |
| 433 | { |
| 434 | va_list args; |
| 435 | uint i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 436 | char printbuffer[CONFIG_SYS_PBSIZE]; |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 437 | |
| 438 | va_start (args, format); |
| 439 | |
| 440 | /* For this to work, printbuffer must be larger than |
| 441 | * anything we ever want to print. |
| 442 | */ |
| 443 | i = vsprintf (printbuffer, format, args); |
| 444 | va_end (args); |
| 445 | |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 446 | #ifdef CONFIG_LOGBUFFER |
wdenk | 228f29a | 2002-12-08 09:53:23 +0000 | [diff] [blame] | 447 | /* Send to the logbuffer */ |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 448 | logbuff_log (printbuffer); |
| 449 | #else |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 450 | /* Send to the stdout file */ |
| 451 | puts (printbuffer); |
wdenk | 56f94be | 2002-11-05 16:35:14 +0000 | [diff] [blame] | 452 | #endif |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 453 | |
| 454 | return 0; |
| 455 | } |
| 456 | |
Wolfgang Denk | 2e5167c | 2010-10-28 20:00:11 +0200 | [diff] [blame] | 457 | #ifdef CONFIG_NEEDS_MANUAL_RELOC |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 458 | void post_reloc (void) |
| 459 | { |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 460 | unsigned int i; |
| 461 | |
| 462 | /* |
| 463 | * We have to relocate the test table manually |
| 464 | */ |
| 465 | for (i = 0; i < post_list_size; i++) { |
| 466 | ulong addr; |
| 467 | struct post_test *test = post_list + i; |
| 468 | |
| 469 | if (test->name) { |
| 470 | addr = (ulong) (test->name) + gd->reloc_off; |
| 471 | test->name = (char *) addr; |
| 472 | } |
| 473 | |
| 474 | if (test->cmd) { |
| 475 | addr = (ulong) (test->cmd) + gd->reloc_off; |
| 476 | test->cmd = (char *) addr; |
| 477 | } |
| 478 | |
| 479 | if (test->desc) { |
| 480 | addr = (ulong) (test->desc) + gd->reloc_off; |
| 481 | test->desc = (char *) addr; |
| 482 | } |
| 483 | |
| 484 | if (test->test) { |
| 485 | addr = (ulong) (test->test) + gd->reloc_off; |
| 486 | test->test = (int (*)(int flags)) addr; |
| 487 | } |
wdenk | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 488 | |
| 489 | if (test->init_f) { |
| 490 | addr = (ulong) (test->init_f) + gd->reloc_off; |
| 491 | test->init_f = (int (*)(void)) addr; |
| 492 | } |
| 493 | |
| 494 | if (test->reloc) { |
| 495 | addr = (ulong) (test->reloc) + gd->reloc_off; |
| 496 | test->reloc = (void (*)(void)) addr; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 497 | |
wdenk | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 498 | test->reloc(); |
| 499 | } |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 500 | } |
| 501 | } |
Peter Tyser | 521af04 | 2009-09-21 11:20:36 -0500 | [diff] [blame] | 502 | #endif |
wdenk | a042ac8 | 2002-09-12 22:36:57 +0000 | [diff] [blame] | 503 | |
wdenk | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 504 | |
| 505 | /* |
| 506 | * Some tests (e.g. SYSMON) need the time when post_init_f started, |
| 507 | * but we cannot use get_timer() at this point. |
| 508 | * |
| 509 | * On PowerPC we implement it using the timebase register. |
| 510 | */ |
| 511 | unsigned long post_time_ms (unsigned long base) |
| 512 | { |
| 513 | #ifdef CONFIG_PPC |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 514 | return (unsigned long)(get_ticks () / (get_tbclk () / CONFIG_SYS_HZ)) - base; |
wdenk | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 515 | #else |
Wolfgang Denk | ad5bb45 | 2007-03-06 18:08:43 +0100 | [diff] [blame] | 516 | #warning "Not implemented yet" |
wdenk | 4532cb6 | 2003-04-27 22:52:51 +0000 | [diff] [blame] | 517 | return 0; /* Not implemented yet */ |
| 518 | #endif |
| 519 | } |