]>
git.ipfire.org Git - people/ms/u-boot.git/blob - post/post.c
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,
29 #ifdef CONFIG_LOGBUFFER
35 #define POST_MAX_NUMBER 32
37 #define BOOTMODE_MAGIC 0xDEAD0000
39 void post_bootmode_init (void)
41 int bootmode
= post_bootmode_get (0);
44 bootmode
= POST_POWERON
;
45 } else if (bootmode
== POST_POWERON
) {
46 bootmode
= POST_POWERNORMAL
;
51 post_word_store (BOOTMODE_MAGIC
| bootmode
);
54 int post_bootmode_get (unsigned int *last_test
)
56 unsigned long word
= post_word_load ();
59 if ((word
& 0xFFFF0000) != BOOTMODE_MAGIC
) {
63 bootmode
= word
& 0xFF;
65 if (last_test
&& (bootmode
& POST_POWERTEST
)) {
66 *last_test
= (word
>> 8) & 0xFF;
72 void post_bootmode_clear (void)
77 static void post_bootmode_test_on (unsigned int last_test
)
79 unsigned long word
= post_word_load ();
81 word
|= POST_POWERTEST
;
83 word
|= (last_test
& 0xFF) << 8;
85 post_word_store (word
);
88 static void post_bootmode_test_off (void)
90 unsigned long word
= post_word_load ();
92 word
&= ~POST_POWERTEST
;
94 post_word_store (word
);
97 static void post_get_flags (int *test_flags
)
99 int flag
[] = { POST_POWERON
, POST_POWERNORMAL
, POST_POWERFAIL
};
100 char *var
[] = { "post_poweron", "post_normal", "post_shutdown" };
101 int varnum
= sizeof (var
) / sizeof (var
[0]);
102 char list
[128]; /* long enough for POST list */
108 for (j
= 0; j
< post_list_size
; j
++) {
109 test_flags
[j
] = post_list
[j
].flags
;
112 for (i
= 0; i
< varnum
; i
++) {
113 if (getenv_r (var
[i
], list
, sizeof (list
)) <= 0)
116 for (j
= 0; j
< post_list_size
; j
++) {
117 test_flags
[j
] &= ~flag
[i
];
123 while (*name
&& *name
== ' ')
128 while (*s
&& *s
!= ' ')
135 for (j
= 0; j
< post_list_size
; j
++) {
136 if (strcmp (post_list
[j
].cmd
, name
) == 0) {
137 test_flags
[j
] |= flag
[i
];
142 if (j
== post_list_size
) {
143 printf ("No such test: %s\n", name
);
151 static int post_run_single (struct post_test
*test
,
152 int test_flags
, int flags
, unsigned int i
)
154 if ((flags
& test_flags
& POST_ALWAYS
) &&
155 (flags
& test_flags
& POST_MEM
)) {
158 if (!(flags
& POST_REBOOT
)) {
159 if ((test_flags
& POST_REBOOT
) && !(flags
& POST_MANUAL
)) {
160 post_bootmode_test_on (i
);
163 post_log ("POST %s ", test
->cmd
);
166 if ((*test
->test
) (flags
) != 0)
167 post_log ("FAILED\n");
169 post_log ("PASSED\n");
171 if ((test_flags
& POST_REBOOT
) && !(flags
& POST_MANUAL
)) {
172 post_bootmode_test_off ();
181 int post_run (char *name
, int flags
)
184 int test_flags
[POST_MAX_NUMBER
];
186 post_get_flags (test_flags
);
191 if (post_bootmode_get (&last
) & POST_POWERTEST
) {
192 if (last
< post_list_size
&&
193 (flags
& test_flags
[last
] & POST_ALWAYS
) &&
194 (flags
& test_flags
[last
] & POST_MEM
)) {
196 post_run_single (post_list
+ last
,
198 flags
| POST_REBOOT
, last
);
200 for (i
= last
+ 1; i
< post_list_size
; i
++) {
201 post_run_single (post_list
+ i
,
207 for (i
= 0; i
< post_list_size
; i
++) {
208 post_run_single (post_list
+ i
,
216 for (i
= 0; i
< post_list_size
; i
++) {
217 if (strcmp (post_list
[i
].cmd
, name
) == 0)
221 if (i
< post_list_size
) {
222 return post_run_single (post_list
+ i
,
231 static int post_info_single (struct post_test
*test
, int full
)
233 if (test
->flags
& POST_MANUAL
) {
236 " %s\n", test
->cmd
, test
->name
, test
->desc
);
238 printf (" %-15s - %s\n", test
->cmd
, test
->name
);
246 int post_info (char *name
)
251 for (i
= 0; i
< post_list_size
; i
++) {
252 post_info_single (post_list
+ i
, 0);
257 for (i
= 0; i
< post_list_size
; i
++) {
258 if (strcmp (post_list
[i
].cmd
, name
) == 0)
262 if (i
< post_list_size
) {
263 return post_info_single (post_list
+ i
, 1);
270 int post_log (char *format
, ...)
274 char printbuffer
[CFG_PBSIZE
];
276 va_start (args
, format
);
278 /* For this to work, printbuffer must be larger than
279 * anything we ever want to print.
281 i
= vsprintf (printbuffer
, format
, args
);
284 #ifdef CONFIG_LOGBUFFER
285 logbuff_log (printbuffer
);
287 /* Send to the stdout file */
294 void post_reloc (void)
296 DECLARE_GLOBAL_DATA_PTR
;
301 * We have to relocate the test table manually
303 for (i
= 0; i
< post_list_size
; i
++) {
305 struct post_test
*test
= post_list
+ i
;
308 addr
= (ulong
) (test
->name
) + gd
->reloc_off
;
309 test
->name
= (char *) addr
;
313 addr
= (ulong
) (test
->cmd
) + gd
->reloc_off
;
314 test
->cmd
= (char *) addr
;
318 addr
= (ulong
) (test
->desc
) + gd
->reloc_off
;
319 test
->desc
= (char *) addr
;
323 addr
= (ulong
) (test
->test
) + gd
->reloc_off
;
324 test
->test
= (int (*)(int flags
)) addr
;
329 #endif /* CONFIG_POST */