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