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