3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #define POST_MAX_NUMBER 32
33 #define BOOTMODE_MAGIC 0xDEAD0000
35 void post_bootmode_init (void)
37 int bootmode = post_bootmode_get (0);
40 bootmode = POST_POWERON;
41 } else if (bootmode == POST_POWERON) {
42 bootmode = POST_POWERNORMAL;
47 post_word_store (BOOTMODE_MAGIC | bootmode);
50 int post_bootmode_get (unsigned int *last_test)
52 unsigned long word = post_word_load ();
55 if ((word & 0xFFFF0000) != BOOTMODE_MAGIC) {
59 bootmode = word & 0xFF;
61 if (last_test && (bootmode & POST_POWERTEST)) {
62 *last_test = (word >> 8) & 0xFF;
68 void post_bootmode_clear (void)
73 static void post_bootmode_test_on (unsigned int last_test)
75 unsigned long word = post_word_load ();
77 word |= POST_POWERTEST;
79 word |= (last_test & 0xFF) << 8;
81 post_word_store (word);
84 static void post_bootmode_test_off (void)
86 unsigned long word = post_word_load ();
88 word &= ~POST_POWERTEST;
90 post_word_store (word);
93 static void post_get_flags (int *test_flags)
95 int flag[] = { POST_POWERON, POST_POWERNORMAL, POST_POWERFAIL };
96 char *var[] = { "post_poweron", "post_normal", "post_shutdown" };
97 int varnum = sizeof (var) / sizeof (var[0]);
98 char list[128]; /* long enough for POST list */
104 for (j = 0; j < post_list_size; j++) {
105 test_flags[j] = post_list[j].flags;
108 for (i = 0; i < varnum; i++) {
109 if (getenv_r (var[i], list, sizeof (list)) <= 0)
112 for (j = 0; j < post_list_size; j++) {
113 test_flags[j] &= ~flag[i];
119 while (*name && *name == ' ')
124 while (*s && *s != ' ')
131 for (j = 0; j < post_list_size; j++) {
132 if (strcmp (post_list[j].cmd, name) == 0) {
133 test_flags[j] |= flag[i];
138 if (j == post_list_size) {
139 printf ("No such test: %s\n", name);
147 static int post_run_single (struct post_test *test,
148 int test_flags, int flags, unsigned int i)
150 if ((flags & test_flags & POST_ALWAYS) &&
151 (flags & test_flags & POST_MEM)) {
154 if (!(flags & POST_REBOOT)) {
155 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
156 post_bootmode_test_on (i);
159 post_log ("START %s\n", test->cmd);
162 if ((*test->test) (flags) != 0)
163 post_log ("FAILED\n");
165 post_log ("PASSED\n");
167 if ((test_flags & POST_REBOOT) && !(flags & POST_MANUAL)) {
168 post_bootmode_test_off ();
177 int post_run (char *name, int flags)
180 int test_flags[POST_MAX_NUMBER];
182 post_get_flags (test_flags);
187 if (post_bootmode_get (&last) & POST_POWERTEST) {
188 if (last < post_list_size &&
189 (flags & test_flags[last] & POST_ALWAYS) &&
190 (flags & test_flags[last] & POST_MEM)) {
192 post_run_single (post_list + last, test_flags[last],
193 flags | POST_REBOOT, last);
195 for (i = last + 1; i < post_list_size; i++) {
196 post_run_single (post_list + i, test_flags[i],
201 for (i = 0; i < post_list_size; i++) {
202 post_run_single (post_list + i, test_flags[i], flags,
209 for (i = 0; i < post_list_size; i++) {
210 if (strcmp (post_list[i].cmd, name) == 0)
214 if (i < post_list_size) {
215 return post_run_single (post_list + i,
224 static int post_info_single (struct post_test *test, int full)
226 if (test->flags & POST_MANUAL) {
229 " %s\n", test->cmd, test->name, test->desc);
231 printf (" %-15s - %s\n", test->cmd, test->name);
239 int post_info (char *name)
244 for (i = 0; i < post_list_size; i++) {
245 post_info_single (post_list + i, 0);
250 for (i = 0; i < post_list_size; i++) {
251 if (strcmp (post_list[i].cmd, name) == 0)
255 if (i < post_list_size) {
256 return post_info_single (post_list + i, 1);
263 int post_log (char *format, ...)
267 char printbuffer[CFG_PBSIZE];
269 va_start (args, format);
271 /* For this to work, printbuffer must be larger than
272 * anything we ever want to print.
274 i = vsprintf (printbuffer, format, args);
277 /* Send to the stdout file */
283 void post_reloc (void)
285 DECLARE_GLOBAL_DATA_PTR;
290 * We have to relocate the test table manually
292 for (i = 0; i < post_list_size; i++) {
294 struct post_test *test = post_list + i;
297 addr = (ulong) (test->name) + gd->reloc_off;
298 test->name = (char *) addr;
302 addr = (ulong) (test->cmd) + gd->reloc_off;
303 test->cmd = (char *) addr;
307 addr = (ulong) (test->desc) + gd->reloc_off;
308 test->desc = (char *) addr;
312 addr = (ulong) (test->test) + gd->reloc_off;
313 test->test = (int (*)(int flags)) addr;
318 #endif /* CONFIG_POST */