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