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