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