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