xref: /OK3568_Linux_fs/u-boot/doc/README.POST (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593SmuzhiyunPower-On-Self-Test support in U-Boot
2*4882a593Smuzhiyun------------------------------------
3*4882a593Smuzhiyun
4*4882a593SmuzhiyunThis project is to support Power-On-Self-Test (POST) in U-Boot.
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun1. High-level requirements
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunThe key requirements for this project are as follows:
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun1) The project shall develop a flexible framework for implementing
11*4882a593Smuzhiyun   and running Power-On-Self-Test in U-Boot. This framework shall
12*4882a593Smuzhiyun   possess the following features:
13*4882a593Smuzhiyun
14*4882a593Smuzhiyun   o) Extensibility
15*4882a593Smuzhiyun
16*4882a593Smuzhiyun      The framework shall allow adding/removing/replacing POST tests.
17*4882a593Smuzhiyun      Also, standalone POST tests shall be supported.
18*4882a593Smuzhiyun
19*4882a593Smuzhiyun   o) Configurability
20*4882a593Smuzhiyun
21*4882a593Smuzhiyun      The framework shall allow run-time configuration of the lists
22*4882a593Smuzhiyun      of tests running on normal/power-fail booting.
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun   o) Controllability
25*4882a593Smuzhiyun
26*4882a593Smuzhiyun      The framework shall support manual running of the POST tests.
27*4882a593Smuzhiyun
28*4882a593Smuzhiyun2) The results of tests shall be saved so that it will be possible to
29*4882a593Smuzhiyun   retrieve them from Linux.
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun3) The following POST tests shall be developed for MPC823E-based
32*4882a593Smuzhiyun   boards:
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun   o) CPU test
35*4882a593Smuzhiyun   o) Cache test
36*4882a593Smuzhiyun   o) Memory test
37*4882a593Smuzhiyun   o) Ethernet test
38*4882a593Smuzhiyun   o) Serial channels test
39*4882a593Smuzhiyun   o) Watchdog timer test
40*4882a593Smuzhiyun   o) RTC test
41*4882a593Smuzhiyun   o) I2C test
42*4882a593Smuzhiyun   o) SPI test
43*4882a593Smuzhiyun   o) USB test
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun4) The LWMON board shall be used for reference.
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun2. Design
48*4882a593Smuzhiyun
49*4882a593SmuzhiyunThis section details the key points of the design for the project.
50*4882a593SmuzhiyunThe whole project can be divided into two independent tasks:
51*4882a593Smuzhiyunenhancing U-Boot/Linux to provide a common framework for running POST
52*4882a593Smuzhiyuntests and developing such tests for particular hardware.
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun2.1. Hardware-independent POST layer
55*4882a593Smuzhiyun
56*4882a593SmuzhiyunA new optional module will be added to U-Boot, which will run POST
57*4882a593Smuzhiyuntests and collect their results at boot time. Also, U-Boot will
58*4882a593Smuzhiyunsupport running POST tests manually at any time by executing a
59*4882a593Smuzhiyunspecial command from the system console.
60*4882a593Smuzhiyun
61*4882a593SmuzhiyunThe list of available POST tests will be configured at U-Boot build
62*4882a593Smuzhiyuntime. The POST layer will allow the developer to add any custom POST
63*4882a593Smuzhiyuntests. All POST tests will be divided into the following groups:
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun  1) Tests running on power-on booting only
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun     This group will contain those tests that run only once on
68*4882a593Smuzhiyun     power-on reset (e.g. watchdog test)
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun  2) Tests running on normal booting only
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun     This group will contain those tests that do not take much
73*4882a593Smuzhiyun     time and can be run on the regular basis (e.g. CPU test)
74*4882a593Smuzhiyun
75*4882a593Smuzhiyun  3) Tests running in special "slow test mode" only
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun     This group will contain POST tests that consume much time
78*4882a593Smuzhiyun     and cannot be run regularly (e.g. strong memory test, I2C test)
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun  4) Manually executed tests
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun     This group will contain those tests that can be run manually.
83*4882a593Smuzhiyun
84*4882a593SmuzhiyunIf necessary, some tests may belong to several groups simultaneously.
85*4882a593SmuzhiyunFor example, SDRAM test may run in both normal and "slow test" mode.
86*4882a593SmuzhiyunIn normal mode, SDRAM test may perform a fast superficial memory test
87*4882a593Smuzhiyunonly, while running in slow test mode it may perform a full memory
88*4882a593Smuzhiyuncheck-up.
89*4882a593Smuzhiyun
90*4882a593SmuzhiyunAlso, all tests will be discriminated by the moment they run at.
91*4882a593SmuzhiyunSpecifically, the following groups will be singled out:
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun  1) Tests running before relocating to RAM
94*4882a593Smuzhiyun
95*4882a593Smuzhiyun     These tests will run immediately after initializing RAM
96*4882a593Smuzhiyun     as to enable modifying it without taking care of its
97*4882a593Smuzhiyun     contents. Basically, this group will contain memory tests
98*4882a593Smuzhiyun     only.
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun  2) Tests running after relocating to RAM
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun     These tests will run immediately before entering the main
103*4882a593Smuzhiyun     loop as to guarantee full hardware initialization.
104*4882a593Smuzhiyun
105*4882a593SmuzhiyunThe POST layer will also distinguish a special group of tests that
106*4882a593Smuzhiyunmay cause system rebooting (e.g. watchdog test). For such tests, the
107*4882a593Smuzhiyunlayer will automatically detect rebooting and will notify the test
108*4882a593Smuzhiyunabout it.
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun2.1.1. POST layer interfaces
111*4882a593Smuzhiyun
112*4882a593SmuzhiyunThis section details the interfaces between the POST layer and the
113*4882a593Smuzhiyunrest of U-Boot.
114*4882a593Smuzhiyun
115*4882a593SmuzhiyunThe following flags will be defined:
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun#define POST_POWERON		0x01	/* test runs on power-on booting */
118*4882a593Smuzhiyun#define POST_NORMAL		0x02	/* test runs on normal booting */
119*4882a593Smuzhiyun#define POST_SLOWTEST		0x04	/* test is slow, enabled by key press */
120*4882a593Smuzhiyun#define POST_POWERTEST		0x08	/* test runs after watchdog reset */
121*4882a593Smuzhiyun#define POST_ROM		0x100	/* test runs in ROM */
122*4882a593Smuzhiyun#define POST_RAM		0x200	/* test runs in RAM */
123*4882a593Smuzhiyun#define POST_MANUAL		0x400	/* test can be executed manually */
124*4882a593Smuzhiyun#define POST_REBOOT		0x800	/* test may cause rebooting */
125*4882a593Smuzhiyun#define POST_PREREL             0x1000  /* test runs before relocation */
126*4882a593Smuzhiyun
127*4882a593SmuzhiyunThe POST layer will export the following interface routines:
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun  o) int post_run(bd_t *bd, char *name, int flags);
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun     This routine will run the test (or the group of tests) specified
132*4882a593Smuzhiyun     by the name and flag arguments. More specifically, if the name
133*4882a593Smuzhiyun     argument is not NULL, the test with this name will be performed,
134*4882a593Smuzhiyun     otherwise all tests running in ROM/RAM (depending on the flag
135*4882a593Smuzhiyun     argument) will be executed. This routine will be called at least
136*4882a593Smuzhiyun     twice with name set to NULL, once from board_init_f() and once
137*4882a593Smuzhiyun     from board_init_r(). The flags argument will also specify the
138*4882a593Smuzhiyun     mode the test is executed in (power-on, normal, power-fail,
139*4882a593Smuzhiyun     manual).
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun  o) void post_reloc(ulong offset);
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun     This routine will be called from board_init_r() and will
144*4882a593Smuzhiyun     relocate the POST test table.
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun  o) int post_info(char *name);
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun     This routine will print the list of all POST tests that can be
149*4882a593Smuzhiyun     executed manually if name is NULL, and the description of a
150*4882a593Smuzhiyun     particular test if name is not NULL.
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun  o) int post_log(char *format, ...);
153*4882a593Smuzhiyun
154*4882a593Smuzhiyun     This routine will be called from POST tests to log their
155*4882a593Smuzhiyun     results. Basically, this routine will print the results to
156*4882a593Smuzhiyun     stderr. The format of the arguments and the return value
157*4882a593Smuzhiyun     will be identical to the printf() routine.
158*4882a593Smuzhiyun
159*4882a593SmuzhiyunAlso, the following board-specific routines will be called from the
160*4882a593SmuzhiyunU-Boot common code:
161*4882a593Smuzhiyun
162*4882a593Smuzhiyun  o) int board_power_mode(void)
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun     This routine will return the mode the system is running in
165*4882a593Smuzhiyun     (POST_POWERON, POST_NORMAL or POST_SHUTDOWN).
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun  o) void board_poweroff(void)
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun     This routine will turn off the power supply of the board. It
170*4882a593Smuzhiyun     will be called on power-fail booting after running all POST
171*4882a593Smuzhiyun     tests.
172*4882a593Smuzhiyun
173*4882a593Smuzhiyun  o) int post_hotkeys_pressed(gd_t *gd)
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun     This routine will scan the keyboard to detect if a magic key
176*4882a593Smuzhiyun     combination has been pressed, or otherwise detect if the
177*4882a593Smuzhiyun     power-on long-running tests shall be executed or not ("normal"
178*4882a593Smuzhiyun     versus "slow" test mode).
179*4882a593Smuzhiyun
180*4882a593SmuzhiyunThe list of available POST tests be kept in the post_tests array
181*4882a593Smuzhiyunfilled at U-Boot build time. The format of entry in this array will
182*4882a593Smuzhiyunbe as follows:
183*4882a593Smuzhiyun
184*4882a593Smuzhiyunstruct post_test {
185*4882a593Smuzhiyun    char *name;
186*4882a593Smuzhiyun    char *cmd;
187*4882a593Smuzhiyun    char *desc;
188*4882a593Smuzhiyun    int flags;
189*4882a593Smuzhiyun    int (*test)(bd_t *bd, int flags);
190*4882a593Smuzhiyun};
191*4882a593Smuzhiyun
192*4882a593Smuzhiyun  o) name
193*4882a593Smuzhiyun
194*4882a593Smuzhiyun     This field will contain a short name of the test, which will be
195*4882a593Smuzhiyun     used in logs and on listing POST tests (e.g. CPU test).
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun  o) cmd
198*4882a593Smuzhiyun
199*4882a593Smuzhiyun     This field will keep a name for identifying the test on manual
200*4882a593Smuzhiyun     testing (e.g. cpu). For more information, refer to section
201*4882a593Smuzhiyun     "Command line interface".
202*4882a593Smuzhiyun
203*4882a593Smuzhiyun  o) desc
204*4882a593Smuzhiyun
205*4882a593Smuzhiyun     This field will contain a detailed description of the test,
206*4882a593Smuzhiyun     which will be printed on user request. For more information, see
207*4882a593Smuzhiyun     section "Command line interface".
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun  o) flags
210*4882a593Smuzhiyun
211*4882a593Smuzhiyun     This field will contain a combination of the bit flags described
212*4882a593Smuzhiyun     above, which will specify the mode the test is running in
213*4882a593Smuzhiyun     (power-on, normal, power-fail or manual mode), the moment it
214*4882a593Smuzhiyun     should be run at (before or after relocating to RAM), whether it
215*4882a593Smuzhiyun     can cause system rebooting or not.
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun  o) test
218*4882a593Smuzhiyun
219*4882a593Smuzhiyun     This field will contain a pointer to the routine that will
220*4882a593Smuzhiyun     perform the test, which will take 2 arguments. The first
221*4882a593Smuzhiyun     argument will be a pointer to the board info structure, while
222*4882a593Smuzhiyun     the second will be a combination of bit flags specifying the
223*4882a593Smuzhiyun     mode the test is running in (POST_POWERON, POST_NORMAL,
224*4882a593Smuzhiyun     POST_SLOWTEST, POST_MANUAL) and whether the last execution of
225*4882a593Smuzhiyun     the test caused system rebooting (POST_REBOOT). The routine will
226*4882a593Smuzhiyun     return 0 on successful execution of the test, and 1 if the test
227*4882a593Smuzhiyun     failed.
228*4882a593Smuzhiyun
229*4882a593SmuzhiyunThe lists of the POST tests that should be run at power-on/normal/
230*4882a593Smuzhiyunpower-fail booting will be kept in the environment. Namely, the
231*4882a593Smuzhiyunfollowing environment variables will be used: post_poweron,
232*4882a593Smuzhiyunpowet_normal, post_slowtest.
233*4882a593Smuzhiyun
234*4882a593Smuzhiyun2.1.2. Test results
235*4882a593Smuzhiyun
236*4882a593SmuzhiyunThe results of tests will be collected by the POST layer. The POST
237*4882a593Smuzhiyunlog will have the following format:
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun...
240*4882a593Smuzhiyun--------------------------------------------
241*4882a593SmuzhiyunSTART <name>
242*4882a593Smuzhiyun<test-specific output>
243*4882a593Smuzhiyun[PASSED|FAILED]
244*4882a593Smuzhiyun--------------------------------------------
245*4882a593Smuzhiyun...
246*4882a593Smuzhiyun
247*4882a593SmuzhiyunBasically, the results of tests will be printed to stderr. This
248*4882a593Smuzhiyunfeature may be enhanced in future to spool the log to a serial line,
249*4882a593Smuzhiyunsave it in non-volatile RAM (NVRAM), transfer it to a dedicated
250*4882a593Smuzhiyunstorage server and etc.
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun2.1.3. Integration issues
253*4882a593Smuzhiyun
254*4882a593SmuzhiyunAll POST-related code will be #ifdef'ed with the CONFIG_POST macro.
255*4882a593SmuzhiyunThis macro will be defined in the config_<board>.h file for those
256*4882a593Smuzhiyunboards that need POST. The CONFIG_POST macro will contain the list of
257*4882a593SmuzhiyunPOST tests for the board. The macro will have the format of array
258*4882a593Smuzhiyuncomposed of post_test structures:
259*4882a593Smuzhiyun
260*4882a593Smuzhiyun#define CONFIG_POST \
261*4882a593Smuzhiyun	{
262*4882a593Smuzhiyun		"On-board peripherals test", "board", \
263*4882a593Smuzhiyun		"  This test performs full check-up of the " \
264*4882a593Smuzhiyun		"on-board hardware.", \
265*4882a593Smuzhiyun		POST_RAM | POST_SLOWTEST, \
266*4882a593Smuzhiyun		&board_post_test \
267*4882a593Smuzhiyun	}
268*4882a593Smuzhiyun
269*4882a593SmuzhiyunA new file, post.h, will be created in the include/ directory. This
270*4882a593Smuzhiyunfile will contain common POST declarations and will define a set of
271*4882a593Smuzhiyunmacros that will be reused for defining CONFIG_POST. As an example,
272*4882a593Smuzhiyunthe following macro may be defined:
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun#define POST_CACHE \
275*4882a593Smuzhiyun	{
276*4882a593Smuzhiyun		"Cache test", "cache", \
277*4882a593Smuzhiyun		"  This test verifies the CPU cache operation.", \
278*4882a593Smuzhiyun		POST_RAM | POST_NORMAL, \
279*4882a593Smuzhiyun		&cache_post_test \
280*4882a593Smuzhiyun	}
281*4882a593Smuzhiyun
282*4882a593SmuzhiyunA new subdirectory will be created in the U-Boot root directory. It
283*4882a593Smuzhiyunwill contain the source code of the POST layer and most of POST
284*4882a593Smuzhiyuntests. Each POST test in this directory will be placed into a
285*4882a593Smuzhiyunseparate file (it will be needed for building standalone tests). Some
286*4882a593SmuzhiyunPOST tests (mainly those for testing peripheral devices) will be
287*4882a593Smuzhiyunlocated in the source files of the drivers for those devices. This
288*4882a593Smuzhiyunway will be used only if the test subtantially uses the driver.
289*4882a593Smuzhiyun
290*4882a593Smuzhiyun2.1.4. Standalone tests
291*4882a593Smuzhiyun
292*4882a593SmuzhiyunThe POST framework will allow to develop and run standalone tests. A
293*4882a593Smuzhiyunuser-space library will be developed to provide the POST interface
294*4882a593Smuzhiyunfunctions to standalone tests.
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun2.1.5. Command line interface
297*4882a593Smuzhiyun
298*4882a593SmuzhiyunA new command, diag, will be added to U-Boot. This command will be
299*4882a593Smuzhiyunused for listing all available hardware tests, getting detailed
300*4882a593Smuzhiyundescriptions of them and running these tests.
301*4882a593Smuzhiyun
302*4882a593SmuzhiyunMore specifically, being run without any arguments, this command will
303*4882a593Smuzhiyunprint the list of all available hardware tests:
304*4882a593Smuzhiyun
305*4882a593Smuzhiyun=> diag
306*4882a593SmuzhiyunAvailable hardware tests:
307*4882a593Smuzhiyun  cache             - cache test
308*4882a593Smuzhiyun  cpu               - CPU test
309*4882a593Smuzhiyun  enet              - SCC/FCC ethernet test
310*4882a593SmuzhiyunUse 'diag [<test1> [<test2>]] ... ' to get more info.
311*4882a593SmuzhiyunUse 'diag run [<test1> [<test2>]] ... ' to run tests.
312*4882a593Smuzhiyun=>
313*4882a593Smuzhiyun
314*4882a593SmuzhiyunIf the first argument to the diag command is not 'run', detailed
315*4882a593Smuzhiyundescriptions of the specified tests will be printed:
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun=> diag cpu cache
318*4882a593Smuzhiyuncpu - CPU test
319*4882a593Smuzhiyun  This test verifies the arithmetic logic unit of CPU.
320*4882a593Smuzhiyuncache - cache test
321*4882a593Smuzhiyun  This test verifies the CPU cache operation.
322*4882a593Smuzhiyun=>
323*4882a593Smuzhiyun
324*4882a593SmuzhiyunIf the first argument to diag is 'run', the specified tests will be
325*4882a593Smuzhiyunexecuted. If no tests are specified, all available tests will be
326*4882a593Smuzhiyunexecuted.
327*4882a593Smuzhiyun
328*4882a593SmuzhiyunIt will be prohibited to execute tests running in ROM manually. The
329*4882a593Smuzhiyun'diag' command will not display such tests and/or run them.
330*4882a593Smuzhiyun
331*4882a593Smuzhiyun2.1.6. Power failure handling
332*4882a593Smuzhiyun
333*4882a593SmuzhiyunThe Linux kernel will be modified to detect power failures and
334*4882a593Smuzhiyunautomatically reboot the system in such cases. It will be assumed
335*4882a593Smuzhiyunthat the power failure causes a system interrupt.
336*4882a593Smuzhiyun
337*4882a593SmuzhiyunTo perform correct system shutdown, the kernel will register a
338*4882a593Smuzhiyunhandler of the power-fail IRQ on booting. Being called, the handler
339*4882a593Smuzhiyunwill run /sbin/reboot using the call_usermodehelper() routine.
340*4882a593Smuzhiyun/sbin/reboot will automatically bring the system down in a secure
341*4882a593Smuzhiyunway. This feature will be configured in/out from the kernel
342*4882a593Smuzhiyunconfiguration file.
343*4882a593Smuzhiyun
344*4882a593SmuzhiyunThe POST layer of U-Boot will check whether the system runs in
345*4882a593Smuzhiyunpower-fail mode. If it does, the system will be powered off after
346*4882a593Smuzhiyunexecuting all hardware tests.
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun2.1.7. Hazardous tests
349*4882a593Smuzhiyun
350*4882a593SmuzhiyunSome tests may cause system rebooting during their execution. For
351*4882a593Smuzhiyunsome tests, this will indicate a failure, while for the Watchdog
352*4882a593Smuzhiyuntest, this means successful operation of the timer.
353*4882a593Smuzhiyun
354*4882a593SmuzhiyunIn order to support such tests, the following scheme will be
355*4882a593Smuzhiyunimplemented. All the tests that may cause system rebooting will have
356*4882a593Smuzhiyunthe POST_REBOOT bit flag set in the flag field of the correspondent
357*4882a593Smuzhiyunpost_test structure. Before starting tests marked with this bit flag,
358*4882a593Smuzhiyunthe POST layer will store an identification number of the test in a
359*4882a593Smuzhiyunlocation in IMMR. On booting, the POST layer will check the value of
360*4882a593Smuzhiyunthis variable and if it is set will skip over the tests preceding the
361*4882a593Smuzhiyunfailed one. On second execution of the failed test, the POST_REBOOT
362*4882a593Smuzhiyunbit flag will be set in the flag argument to the test routine. This
363*4882a593Smuzhiyunwill allow to detect system rebooting on the previous iteration. For
364*4882a593Smuzhiyunexample, the watchdog timer test may have the following
365*4882a593Smuzhiyundeclaration/body:
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun...
368*4882a593Smuzhiyun#define POST_WATCHDOG \
369*4882a593Smuzhiyun	{
370*4882a593Smuzhiyun		"Watchdog timer test", "watchdog", \
371*4882a593Smuzhiyun		"  This test checks the watchdog timer.", \
372*4882a593Smuzhiyun		POST_RAM | POST_POWERON | POST_REBOOT, \
373*4882a593Smuzhiyun		&watchdog_post_test \
374*4882a593Smuzhiyun	}
375*4882a593Smuzhiyun...
376*4882a593Smuzhiyun
377*4882a593Smuzhiyun...
378*4882a593Smuzhiyunint watchdog_post_test(bd_t *bd, int flags)
379*4882a593Smuzhiyun{
380*4882a593Smuzhiyun	unsigned long start_time;
381*4882a593Smuzhiyun
382*4882a593Smuzhiyun	if (flags & POST_REBOOT) {
383*4882a593Smuzhiyun		/* Test passed */
384*4882a593Smuzhiyun		return 0;
385*4882a593Smuzhiyun	} else {
386*4882a593Smuzhiyun		/* disable interrupts */
387*4882a593Smuzhiyun		disable_interrupts();
388*4882a593Smuzhiyun		/* 10-second delay */
389*4882a593Smuzhiyun		...
390*4882a593Smuzhiyun		/* if we've reached this, the watchdog timer does not work */
391*4882a593Smuzhiyun		enable_interrupts();
392*4882a593Smuzhiyun		return 1;
393*4882a593Smuzhiyun	}
394*4882a593Smuzhiyun}
395*4882a593Smuzhiyun...
396*4882a593Smuzhiyun
397*4882a593Smuzhiyun2.2. Hardware-specific details
398*4882a593Smuzhiyun
399*4882a593SmuzhiyunThis project will also develop a set of POST tests for MPC8xx- based
400*4882a593Smuzhiyunsystems. This section provides technical details of how it will be
401*4882a593Smuzhiyundone.
402*4882a593Smuzhiyun
403*4882a593Smuzhiyun2.2.1. Generic PPC tests
404*4882a593Smuzhiyun
405*4882a593SmuzhiyunThe following generic POST tests will be developed:
406*4882a593Smuzhiyun
407*4882a593Smuzhiyun  o) CPU test
408*4882a593Smuzhiyun
409*4882a593Smuzhiyun     This test will check the arithmetic logic unit (ALU) of CPU. The
410*4882a593Smuzhiyun     test will take several milliseconds and will run on normal
411*4882a593Smuzhiyun     booting.
412*4882a593Smuzhiyun
413*4882a593Smuzhiyun  o) Cache test
414*4882a593Smuzhiyun
415*4882a593Smuzhiyun     This test will verify the CPU cache (L1 cache). The test will
416*4882a593Smuzhiyun     run on normal booting.
417*4882a593Smuzhiyun
418*4882a593Smuzhiyun  o) Memory test
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun     This test will examine RAM and check it for errors. The test
421*4882a593Smuzhiyun     will always run on booting. On normal booting, only a limited
422*4882a593Smuzhiyun     amount of RAM will be checked. On power-fail booting a fool
423*4882a593Smuzhiyun     memory check-up will be performed.
424*4882a593Smuzhiyun
425*4882a593Smuzhiyun2.2.1.1. CPU test
426*4882a593Smuzhiyun
427*4882a593SmuzhiyunThis test will verify the following ALU instructions:
428*4882a593Smuzhiyun
429*4882a593Smuzhiyun  o) Condition register istructions
430*4882a593Smuzhiyun
431*4882a593Smuzhiyun     This group will contain: mtcrf, mfcr, mcrxr, crand, crandc,
432*4882a593Smuzhiyun     cror, crorc, crxor, crnand, crnor, creqv, mcrf.
433*4882a593Smuzhiyun
434*4882a593Smuzhiyun     The mtcrf/mfcr instructions will be tested by loading different
435*4882a593Smuzhiyun     values into the condition register (mtcrf), moving its value to
436*4882a593Smuzhiyun     a general-purpose register (mfcr) and comparing this value with
437*4882a593Smuzhiyun     the expected one. The mcrxr instruction will be tested by
438*4882a593Smuzhiyun     loading a fixed value into the XER register (mtspr), moving XER
439*4882a593Smuzhiyun     value to the condition register (mcrxr), moving it to a
440*4882a593Smuzhiyun     general-purpose register (mfcr) and comparing the value of this
441*4882a593Smuzhiyun     register with the expected one. The rest of instructions will be
442*4882a593Smuzhiyun     tested by loading a fixed value into the condition register
443*4882a593Smuzhiyun     (mtcrf), executing each instruction several times to modify all
444*4882a593Smuzhiyun     4-bit condition fields, moving the value of the conditional
445*4882a593Smuzhiyun     register to a general-purpose register (mfcr) and comparing it
446*4882a593Smuzhiyun     with the expected one.
447*4882a593Smuzhiyun
448*4882a593Smuzhiyun  o) Integer compare instructions
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun     This group will contain: cmp, cmpi, cmpl, cmpli.
451*4882a593Smuzhiyun
452*4882a593Smuzhiyun     To verify these instructions the test will run them with
453*4882a593Smuzhiyun     different combinations of operands, read the condition register
454*4882a593Smuzhiyun     value and compare it with the expected one. More specifically,
455*4882a593Smuzhiyun     the test will contain a pre-built table containing the
456*4882a593Smuzhiyun     description of each test case: the instruction, the values of
457*4882a593Smuzhiyun     the operands, the condition field to save the result in and the
458*4882a593Smuzhiyun     expected result.
459*4882a593Smuzhiyun
460*4882a593Smuzhiyun  o) Arithmetic instructions
461*4882a593Smuzhiyun
462*4882a593Smuzhiyun     This group will contain: add, addc, adde, addme, addze, subf,
463*4882a593Smuzhiyun     subfc, subfe, subme, subze, mullw, mulhw, mulhwu, divw, divwu,
464*4882a593Smuzhiyun     extsb, extsh.
465*4882a593Smuzhiyun
466*4882a593Smuzhiyun     The test will contain a pre-built table of instructions,
467*4882a593Smuzhiyun     operands, expected results and expected states of the condition
468*4882a593Smuzhiyun     register. For each table entry, the test will cyclically use
469*4882a593Smuzhiyun     different sets of operand registers and result registers. For
470*4882a593Smuzhiyun     example, for instructions that use 3 registers on the first
471*4882a593Smuzhiyun     iteration r0/r1 will be used as operands and r2 for result. On
472*4882a593Smuzhiyun     the second iteration, r1/r2 will be used as operands and r3 as
473*4882a593Smuzhiyun     for result and so on. This will enable to verify all
474*4882a593Smuzhiyun     general-purpose registers.
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun  o) Logic instructions
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun     This group will contain: and, andc, andi, andis, or, orc, ori,
479*4882a593Smuzhiyun     oris, xor, xori, xoris, nand, nor, neg, eqv, cntlzw.
480*4882a593Smuzhiyun
481*4882a593Smuzhiyun     The test scheme will be identical to that from the previous
482*4882a593Smuzhiyun     point.
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun  o) Shift instructions
485*4882a593Smuzhiyun
486*4882a593Smuzhiyun     This group will contain: slw, srw, sraw, srawi, rlwinm, rlwnm,
487*4882a593Smuzhiyun     rlwimi
488*4882a593Smuzhiyun
489*4882a593Smuzhiyun     The test scheme will be identical to that from the previous
490*4882a593Smuzhiyun     point.
491*4882a593Smuzhiyun
492*4882a593Smuzhiyun  o) Branch instructions
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun     This group will contain: b, bl, bc.
495*4882a593Smuzhiyun
496*4882a593Smuzhiyun     The first 2 instructions (b, bl) will be verified by jumping to
497*4882a593Smuzhiyun     a fixed address and checking whether control was transferred to
498*4882a593Smuzhiyun     that very point. For the bl instruction the value of the link
499*4882a593Smuzhiyun     register will be checked as well (using mfspr). To verify the bc
500*4882a593Smuzhiyun     instruction various combinations of the BI/BO fields, the CTR
501*4882a593Smuzhiyun     and the condition register values will be checked. The list of
502*4882a593Smuzhiyun     such combinations will be pre-built and linked in U-Boot at
503*4882a593Smuzhiyun     build time.
504*4882a593Smuzhiyun
505*4882a593Smuzhiyun  o) Load/store instructions
506*4882a593Smuzhiyun
507*4882a593Smuzhiyun     This group will contain: lbz(x)(u), lhz(x)(u), lha(x)(u),
508*4882a593Smuzhiyun     lwz(x)(u), stb(x)(u), sth(x)(u), stw(x)(u).
509*4882a593Smuzhiyun
510*4882a593Smuzhiyun     All operations will be performed on a 16-byte array. The array
511*4882a593Smuzhiyun     will be 4-byte aligned. The base register will point to offset
512*4882a593Smuzhiyun     8. The immediate offset (index register) will range in [-8 ...
513*4882a593Smuzhiyun     +7]. The test cases will be composed so that they will not cause
514*4882a593Smuzhiyun     alignment exceptions. The test will contain a pre-built table
515*4882a593Smuzhiyun     describing all test cases. For store instructions, the table
516*4882a593Smuzhiyun     entry will contain: the instruction opcode, the value of the
517*4882a593Smuzhiyun     index register and the value of the source register. After
518*4882a593Smuzhiyun     executing the instruction, the test will verify the contents of
519*4882a593Smuzhiyun     the array and the value of the base register (it must change for
520*4882a593Smuzhiyun     "store with update" instructions). For load instructions, the
521*4882a593Smuzhiyun     table entry will contain: the instruction opcode, the array
522*4882a593Smuzhiyun     contents, the value of the index register and the expected value
523*4882a593Smuzhiyun     of the destination register. After executing the instruction,
524*4882a593Smuzhiyun     the test will verify the value of the destination register and
525*4882a593Smuzhiyun     the value of the base register (it must change for "load with
526*4882a593Smuzhiyun     update" instructions).
527*4882a593Smuzhiyun
528*4882a593Smuzhiyun  o) Load/store multiple/string instructions
529*4882a593Smuzhiyun
530*4882a593Smuzhiyun
531*4882a593SmuzhiyunThe CPU test will run in RAM in order to allow run-time modification
532*4882a593Smuzhiyunof the code to reduce the memory footprint.
533*4882a593Smuzhiyun
534*4882a593Smuzhiyun2.2.1.2 Special-Purpose Registers Tests
535*4882a593Smuzhiyun
536*4882a593SmuzhiyunTBD.
537*4882a593Smuzhiyun
538*4882a593Smuzhiyun2.2.1.3. Cache test
539*4882a593Smuzhiyun
540*4882a593SmuzhiyunTo verify the data cache operation the following test scenarios will
541*4882a593Smuzhiyunbe used:
542*4882a593Smuzhiyun
543*4882a593Smuzhiyun  1) Basic test #1
544*4882a593Smuzhiyun
545*4882a593Smuzhiyun    - turn on the data cache
546*4882a593Smuzhiyun    - switch the data cache to write-back or write-through mode
547*4882a593Smuzhiyun    - invalidate the data cache
548*4882a593Smuzhiyun    - write the negative pattern to a cached area
549*4882a593Smuzhiyun    - read the area
550*4882a593Smuzhiyun
551*4882a593Smuzhiyun    The negative pattern must be read at the last step
552*4882a593Smuzhiyun
553*4882a593Smuzhiyun  2) Basic test #2
554*4882a593Smuzhiyun
555*4882a593Smuzhiyun    - turn on the data cache
556*4882a593Smuzhiyun    - switch the data cache to write-back or write-through mode
557*4882a593Smuzhiyun    - invalidate the data cache
558*4882a593Smuzhiyun    - write the zero pattern to a cached area
559*4882a593Smuzhiyun    - turn off the data cache
560*4882a593Smuzhiyun    - write the negative pattern to the area
561*4882a593Smuzhiyun    - turn on the data cache
562*4882a593Smuzhiyun    - read the area
563*4882a593Smuzhiyun
564*4882a593Smuzhiyun    The negative pattern must be read at the last step
565*4882a593Smuzhiyun
566*4882a593Smuzhiyun  3) Write-through mode test
567*4882a593Smuzhiyun
568*4882a593Smuzhiyun    - turn on the data cache
569*4882a593Smuzhiyun    - switch the data cache to write-through mode
570*4882a593Smuzhiyun    - invalidate the data cache
571*4882a593Smuzhiyun    - write the zero pattern to a cached area
572*4882a593Smuzhiyun    - flush the data cache
573*4882a593Smuzhiyun    - write the negative pattern to the area
574*4882a593Smuzhiyun    - turn off the data cache
575*4882a593Smuzhiyun    - read the area
576*4882a593Smuzhiyun
577*4882a593Smuzhiyun    The negative pattern must be read at the last step
578*4882a593Smuzhiyun
579*4882a593Smuzhiyun  4) Write-back mode test
580*4882a593Smuzhiyun
581*4882a593Smuzhiyun    - turn on the data cache
582*4882a593Smuzhiyun    - switch the data cache to write-back mode
583*4882a593Smuzhiyun    - invalidate the data cache
584*4882a593Smuzhiyun    - write the negative pattern to a cached area
585*4882a593Smuzhiyun    - flush the data cache
586*4882a593Smuzhiyun    - write the zero pattern to the area
587*4882a593Smuzhiyun    - invalidate the data cache
588*4882a593Smuzhiyun    - read the area
589*4882a593Smuzhiyun
590*4882a593Smuzhiyun    The negative pattern must be read at the last step
591*4882a593Smuzhiyun
592*4882a593SmuzhiyunTo verify the instruction cache operation the following test
593*4882a593Smuzhiyunscenarios will be used:
594*4882a593Smuzhiyun
595*4882a593Smuzhiyun  1) Basic test #1
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun    - turn on the instruction cache
598*4882a593Smuzhiyun    - unlock the entire instruction cache
599*4882a593Smuzhiyun    - invalidate the instruction cache
600*4882a593Smuzhiyun    - lock a branch instruction in the instruction cache
601*4882a593Smuzhiyun    - replace the branch instruction with "nop"
602*4882a593Smuzhiyun    - jump to the branch instruction
603*4882a593Smuzhiyun    - check that the branch instruction was executed
604*4882a593Smuzhiyun
605*4882a593Smuzhiyun  2) Basic test #2
606*4882a593Smuzhiyun
607*4882a593Smuzhiyun    - turn on the instruction cache
608*4882a593Smuzhiyun    - unlock the entire instruction cache
609*4882a593Smuzhiyun    - invalidate the instruction cache
610*4882a593Smuzhiyun    - jump to a branch instruction
611*4882a593Smuzhiyun    - check that the branch instruction was executed
612*4882a593Smuzhiyun    - replace the branch instruction with "nop"
613*4882a593Smuzhiyun    - invalidate the instruction cache
614*4882a593Smuzhiyun    - jump to the branch instruction
615*4882a593Smuzhiyun    - check that the "nop" instruction was executed
616*4882a593Smuzhiyun
617*4882a593SmuzhiyunThe CPU test will run in RAM in order to allow run-time modification
618*4882a593Smuzhiyunof the code.
619*4882a593Smuzhiyun
620*4882a593Smuzhiyun2.2.1.4. Memory test
621*4882a593Smuzhiyun
622*4882a593SmuzhiyunThe memory test will verify RAM using sequential writes and reads
623*4882a593Smuzhiyunto/from RAM. Specifically, there will be several test cases that will
624*4882a593Smuzhiyunuse different patterns to verify RAM. Each test case will first fill
625*4882a593Smuzhiyuna region of RAM with one pattern and then read the region back and
626*4882a593Smuzhiyuncompare its contents with the pattern. The following patterns will be
627*4882a593Smuzhiyunused:
628*4882a593Smuzhiyun
629*4882a593Smuzhiyun 1) zero pattern (0x00000000)
630*4882a593Smuzhiyun 2) negative pattern (0xffffffff)
631*4882a593Smuzhiyun 3) checkerboard pattern (0x55555555, 0xaaaaaaaa)
632*4882a593Smuzhiyun 4) bit-flip pattern ((1 << (offset % 32)), ~(1 << (offset % 32)))
633*4882a593Smuzhiyun 5) address pattern (offset, ~offset)
634*4882a593Smuzhiyun
635*4882a593SmuzhiyunPatterns #1, #2 will help to find unstable bits. Patterns #3, #4 will
636*4882a593Smuzhiyunbe used to detect adherent bits, i.e. bits whose state may randomly
637*4882a593Smuzhiyunchange if adjacent bits are modified. The last pattern will be used
638*4882a593Smuzhiyunto detect far-located errors, i.e. situations when writing to one
639*4882a593Smuzhiyunlocation modifies an area located far from it. Also, usage of the
640*4882a593Smuzhiyunlast pattern will help to detect memory controller misconfigurations
641*4882a593Smuzhiyunwhen RAM represents a cyclically repeated portion of a smaller size.
642*4882a593Smuzhiyun
643*4882a593SmuzhiyunBeing run in normal mode, the test will verify only small 4Kb regions
644*4882a593Smuzhiyunof RAM around each 1Mb boundary. For example, for 64Mb RAM the
645*4882a593Smuzhiyunfollowing areas will be verified: 0x00000000-0x00000800,
646*4882a593Smuzhiyun0x000ff800-0x00100800, 0x001ff800-0x00200800, ..., 0x03fff800-
647*4882a593Smuzhiyun0x04000000. If the test is run in power-fail mode, it will verify the
648*4882a593Smuzhiyunwhole RAM.
649*4882a593Smuzhiyun
650*4882a593SmuzhiyunThe memory test will run in ROM before relocating U-Boot to RAM in
651*4882a593Smuzhiyunorder to allow RAM modification without saving its contents.
652*4882a593Smuzhiyun
653*4882a593Smuzhiyun2.2.2. Common tests
654*4882a593Smuzhiyun
655*4882a593SmuzhiyunThis section describes tests that are not based on any hardware
656*4882a593Smuzhiyunpeculiarities and use common U-Boot interfaces only. These tests do
657*4882a593Smuzhiyunnot need any modifications for porting them to another board/CPU.
658*4882a593Smuzhiyun
659*4882a593Smuzhiyun2.2.2.1. I2C test
660*4882a593Smuzhiyun
661*4882a593SmuzhiyunFor verifying the I2C bus, a full I2C bus scanning will be performed
662*4882a593Smuzhiyunusing the i2c_probe() routine. If a board defines
663*4882a593SmuzhiyunCONFIG_SYS_POST_I2C_ADDRS the I2C test will pass if all devices
664*4882a593Smuzhiyunlisted in CONFIG_SYS_POST_I2C_ADDRS are found, and no additional
665*4882a593Smuzhiyundevices are detected.  If CONFIG_SYS_POST_I2C_ADDRS is not defined
666*4882a593Smuzhiyunthe test will pass if any I2C device is found.
667*4882a593Smuzhiyun
668*4882a593SmuzhiyunThe CONFIG_SYS_POST_I2C_IGNORES define can be used to list I2C
669*4882a593Smuzhiyundevices which may or may not be present when using
670*4882a593SmuzhiyunCONFIG_SYS_POST_I2C_ADDRS.  The I2C POST test will pass regardless
671*4882a593Smuzhiyunif the devices in CONFIG_SYS_POST_I2C_IGNORES are found or not.
672*4882a593SmuzhiyunThis is useful in cases when I2C devices are optional (eg on a
673*4882a593Smuzhiyundaughtercard that may or may not be present) or not critical
674*4882a593Smuzhiyunto board operation.
675*4882a593Smuzhiyun
676*4882a593Smuzhiyun2.2.2.2. Watchdog timer test
677*4882a593Smuzhiyun
678*4882a593SmuzhiyunTo test the watchdog timer the scheme mentioned above (refer to
679*4882a593Smuzhiyunsection "Hazardous tests") will be used. Namely, this test will be
680*4882a593Smuzhiyunmarked with the POST_REBOOT bit flag. On the first iteration, the
681*4882a593Smuzhiyuntest routine will make a 10-second delay. If the system does not
682*4882a593Smuzhiyunreboot during this delay, the watchdog timer is not operational and
683*4882a593Smuzhiyunthe test fails. If the system reboots, on the second iteration the
684*4882a593SmuzhiyunPOST_REBOOT bit will be set in the flag argument to the test routine.
685*4882a593SmuzhiyunThe test routine will check this bit and report a success if it is
686*4882a593Smuzhiyunset.
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun2.2.2.3. RTC test
689*4882a593Smuzhiyun
690*4882a593SmuzhiyunThe RTC test will use the rtc_get()/rtc_set() routines. The following
691*4882a593Smuzhiyunfeatures will be verified:
692*4882a593Smuzhiyun
693*4882a593Smuzhiyun  o) Time uniformity
694*4882a593Smuzhiyun
695*4882a593Smuzhiyun     This will be verified by reading RTC in polling within a short
696*4882a593Smuzhiyun     period of time (5-10 seconds).
697*4882a593Smuzhiyun
698*4882a593Smuzhiyun  o) Passing month boundaries
699*4882a593Smuzhiyun
700*4882a593Smuzhiyun     This will be checked by setting RTC to a second before a month
701*4882a593Smuzhiyun     boundary and reading it after its passing the boundary. The test
702*4882a593Smuzhiyun     will be performed for both leap- and nonleap-years.
703*4882a593Smuzhiyun
704*4882a593Smuzhiyun2.2.3. MPC8xx peripherals tests
705*4882a593Smuzhiyun
706*4882a593SmuzhiyunThis project will develop a set of tests verifying the peripheral
707*4882a593Smuzhiyununits of MPC8xx processors. Namely, the following controllers of the
708*4882a593SmuzhiyunMPC8xx communication processor module (CPM) will be tested:
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun  o) Serial Management Controllers (SMC)
711*4882a593Smuzhiyun
712*4882a593Smuzhiyun  o) Serial Communication Controllers (SCC)
713*4882a593Smuzhiyun
714*4882a593Smuzhiyun2.2.3.1. Ethernet tests (SCC)
715*4882a593Smuzhiyun
716*4882a593SmuzhiyunThe internal (local) loopback mode will be used to test SCC. To do
717*4882a593Smuzhiyunthat the controllers will be configured accordingly and several
718*4882a593Smuzhiyunpackets will be transmitted. These tests may be enhanced in future to
719*4882a593Smuzhiyunuse external loopback for testing. That will need appropriate
720*4882a593Smuzhiyunreconfiguration of the physical interface chip.
721*4882a593Smuzhiyun
722*4882a593SmuzhiyunThe test routines for the SCC ethernet tests will be located in
723*4882a593Smuzhiyunarch/powerpc/cpu/mpc8xx/scc.c.
724*4882a593Smuzhiyun
725*4882a593Smuzhiyun2.2.3.2. UART tests (SMC/SCC)
726*4882a593Smuzhiyun
727*4882a593SmuzhiyunTo perform these tests the internal (local) loopback mode will be
728*4882a593Smuzhiyunused. The SMC/SCC controllers will be configured to connect the
729*4882a593Smuzhiyuntransmitter output to the receiver input. After that, several bytes
730*4882a593Smuzhiyunwill be transmitted. These tests may be enhanced to make to perform
731*4882a593Smuzhiyun"external" loopback test using a loopback cable. In this case, the
732*4882a593Smuzhiyuntest will be executed manually.
733*4882a593Smuzhiyun
734*4882a593SmuzhiyunThe test routine for the SMC/SCC UART tests will be located in
735*4882a593Smuzhiyunarch/powerpc/cpu/mpc8xx/serial.c.
736*4882a593Smuzhiyun
737*4882a593Smuzhiyun2.2.3.3. USB test
738*4882a593Smuzhiyun
739*4882a593SmuzhiyunTBD
740*4882a593Smuzhiyun
741*4882a593Smuzhiyun2.2.3.4. SPI test
742*4882a593Smuzhiyun
743*4882a593SmuzhiyunTBD
744