xref: /openbmc/u-boot/include/bootstage.h (revision 150c2493)
1 /*
2  * This file implements recording of each stage of the boot process. It is
3  * intended to implement timing of each stage, reporting this information
4  * to the user and passing it to the OS for logging / further analysis.
5  *
6  * Copyright (c) 2011 The Chromium OS Authors.
7  * See file CREDITS for list of people who contributed to this
8  * project.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License as
12  * published by the Free Software Foundation; either version 2 of
13  * the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307 USA
24  */
25 
26 #ifndef _BOOTSTAGE_H
27 #define _BOOTSTAGE_H
28 
29 /* The number of boot stage records available for the user */
30 #ifndef CONFIG_BOOTSTAGE_USER_COUNT
31 #define CONFIG_BOOTSTAGE_USER_COUNT	20
32 #endif
33 
34 /*
35  * A list of boot stages that we know about. Each of these indicates the
36  * state that we are at, and the action that we are about to perform. For
37  * errors, we issue an error for an item when it fails. Therefore the
38  * normal sequence is:
39  *
40  * progress action1
41  * progress action2
42  * progress action3
43  *
44  * and an error condition where action 3 failed would be:
45  *
46  * progress action1
47  * progress action2
48  * progress action3
49  * error on action3
50  */
51 enum bootstage_id {
52 	BOOTSTAGE_ID_START = 0,
53 	BOOTSTAGE_ID_CHECK_MAGIC,	/* Checking image magic */
54 	BOOTSTAGE_ID_CHECK_HEADER,	/* Checking image header */
55 	BOOTSTAGE_ID_CHECK_CHECKSUM,	/* Checking image checksum */
56 	BOOTSTAGE_ID_CHECK_ARCH,	/* Checking architecture */
57 
58 	BOOTSTAGE_ID_CHECK_IMAGETYPE = 5,/* Checking image type */
59 	BOOTSTAGE_ID_DECOMP_IMAGE,	/* Decompressing image */
60 	BOOTSTAGE_ID_KERNEL_LOADED,	/* Kernel has been loaded */
61 	BOOTSTAGE_ID_DECOMP_UNIMPL = 7,	/* Odd decompression algorithm */
62 	BOOTSTAGE_ID_CHECK_BOOT_OS,	/* Calling OS-specific boot function */
63 	BOOTSTAGE_ID_BOOT_OS_RETURNED,	/* Tried to boot OS, but it returned */
64 	BOOTSTAGE_ID_CHECK_RAMDISK = 9,	/* Checking ram disk */
65 
66 	BOOTSTAGE_ID_RD_MAGIC,		/* Checking ram disk magic */
67 	BOOTSTAGE_ID_RD_HDR_CHECKSUM,	/* Checking ram disk heder checksum */
68 	BOOTSTAGE_ID_RD_CHECKSUM,	/* Checking ram disk checksum */
69 	BOOTSTAGE_ID_COPY_RAMDISK = 12,	/* Copying ram disk into place */
70 	BOOTSTAGE_ID_RAMDISK,		/* Checking for valid ramdisk */
71 	BOOTSTAGE_ID_NO_RAMDISK,	/* No ram disk found (not an error) */
72 
73 	BOOTSTAGE_ID_RUN_OS	= 15,	/* Exiting U-Boot, entering OS */
74 
75 	BOOTSTAGE_ID_NEED_RESET = 30,
76 	BOOTSTAGE_ID_POST_FAIL,		/* Post failure */
77 	BOOTSTAGE_ID_POST_FAIL_R,	/* Post failure reported after reloc */
78 
79 	/*
80 	 * This set is reported ony by x86, and the meaning is different. In
81 	 * this case we are reporting completion of a particular stage.
82 	 * This should probably change in he x86 code (which doesn't report
83 	 * errors in any case), but discussion this can perhaps wait until we
84 	 * have a generic board implementation.
85 	 */
86 	BOOTSTAGE_ID_BOARD_INIT_R,	/* We have relocated */
87 	BOOTSTAGE_ID_BOARD_GLOBAL_DATA,	/* Global data is set up */
88 
89 	BOOTSTAGE_ID_BOARD_INIT_SEQ,	/* We completed the init sequence */
90 	BOOTSTAGE_ID_BOARD_FLASH,	/* We have configured flash banks */
91 	BOOTSTAGE_ID_BOARD_FLASH_37,	/* In case you didn't hear... */
92 	BOOTSTAGE_ID_BOARD_ENV,		/* Environment is relocated & ready */
93 	BOOTSTAGE_ID_BOARD_PCI,		/* PCI is up */
94 
95 	BOOTSTAGE_ID_BOARD_INTERRUPTS,	/* Exceptions / interrupts ready */
96 	BOOTSTAGE_ID_BOARD_DONE,	/* Board init done, off to main loop */
97 	/* ^^^ here ends the x86 sequence */
98 
99 	/* Boot stages related to loading a kernel from an IDE device */
100 	BOOTSTAGE_ID_IDE_START = 41,
101 	BOOTSTAGE_ID_IDE_ADDR,
102 	BOOTSTAGE_ID_IDE_BOOT_DEVICE,
103 	BOOTSTAGE_ID_IDE_TYPE,
104 
105 	BOOTSTAGE_ID_IDE_PART,
106 	BOOTSTAGE_ID_IDE_PART_INFO,
107 	BOOTSTAGE_ID_IDE_PART_TYPE,
108 	BOOTSTAGE_ID_IDE_PART_READ,
109 	BOOTSTAGE_ID_IDE_FORMAT,
110 
111 	BOOTSTAGE_ID_IDE_CHECKSUM,	/* 50 */
112 	BOOTSTAGE_ID_IDE_READ,
113 
114 	/* Boot stages related to loading a kernel from an NAND device */
115 	BOOTSTAGE_ID_NAND_PART,
116 	BOOTSTAGE_ID_NAND_SUFFIX,
117 	BOOTSTAGE_ID_NAND_BOOT_DEVICE,
118 	BOOTSTAGE_ID_NAND_HDR_READ = 55,
119 	BOOTSTAGE_ID_NAND_AVAILABLE = 55,
120 	BOOTSTAGE_ID_NAND_TYPE = 57,
121 	BOOTSTAGE_ID_NAND_READ,
122 
123 	/* Boot stages related to loading a kernel from an network device */
124 	BOOTSTAGE_ID_NET_CHECKSUM = 60,
125 	BOOTSTAGE_ID_NET_ETH_START = 64,
126 	BOOTSTAGE_ID_NET_ETH_INIT,
127 
128 	BOOTSTAGE_ID_NET_START = 80,
129 	BOOTSTAGE_ID_NET_NETLOOP_OK,
130 	BOOTSTAGE_ID_NET_LOADED,
131 	BOOTSTAGE_ID_NET_DONE_ERR,
132 	BOOTSTAGE_ID_NET_DONE,
133 
134 	/*
135 	 * Boot stages related to loading a FIT image. Some of these are a
136 	 * bit wonky.
137 	 */
138 	BOOTSTAGE_ID_FIT_FORMAT = 100,
139 	BOOTSTAGE_ID_FIT_NO_UNIT_NAME,
140 	BOOTSTAGE_ID_FIT_UNIT_NAME,
141 	BOOTSTAGE_ID_FIT_CONFIG,
142 	BOOTSTAGE_ID_FIT_CHECK_SUBIMAGE,
143 	BOOTSTAGE_ID_FIT_CHECK_HASH = 104,
144 
145 	BOOTSTAGE_ID_FIT_CHECK_ARCH,
146 	BOOTSTAGE_ID_FIT_CHECK_KERNEL,
147 	BOOTSTAGE_ID_FIT_CHECKED,
148 
149 	BOOTSTAGE_ID_FIT_KERNEL_INFO_ERR = 107,
150 	BOOTSTAGE_ID_FIT_KERNEL_INFO,
151 	BOOTSTAGE_ID_FIT_TYPE,
152 
153 	BOOTSTAGE_ID_FIT_COMPRESSION,
154 	BOOTSTAGE_ID_FIT_OS,
155 	BOOTSTAGE_ID_FIT_LOADADDR,
156 	BOOTSTAGE_ID_OVERWRITTEN,
157 
158 	BOOTSTAGE_ID_FIT_RD_FORMAT = 120,
159 	BOOTSTAGE_ID_FIT_RD_FORMAT_OK,
160 	BOOTSTAGE_ID_FIT_RD_NO_UNIT_NAME,
161 	BOOTSTAGE_ID_FIT_RD_UNIT_NAME,
162 	BOOTSTAGE_ID_FIT_RD_SUBNODE,
163 
164 	BOOTSTAGE_ID_FIT_RD_CHECK,
165 	BOOTSTAGE_ID_FIT_RD_HASH = 125,
166 	BOOTSTAGE_ID_FIT_RD_CHECK_ALL,
167 	BOOTSTAGE_ID_FIT_RD_GET_DATA,
168 	BOOTSTAGE_ID_FIT_RD_CHECK_ALL_OK = 127,
169 	BOOTSTAGE_ID_FIT_RD_GET_DATA_OK,
170 	BOOTSTAGE_ID_FIT_RD_LOAD,
171 
172 	BOOTSTAGE_ID_IDE_FIT_READ = 140,
173 	BOOTSTAGE_ID_IDE_FIT_READ_OK,
174 
175 	BOOTSTAGE_ID_NAND_FIT_READ = 150,
176 	BOOTSTAGE_ID_NAND_FIT_READ_OK,
177 
178 	/*
179 	 * These boot stages are new, higher level, and not directly related
180 	 * to the old boot progress numbers. They are useful for recording
181 	 * rough boot timing information.
182 	 */
183 	BOOTSTAGE_ID_AWAKE,
184 	BOOTSTAGE_ID_START_UBOOT_F,
185 	BOOTSTAGE_ID_START_UBOOT_R,
186 	BOOTSTAGE_ID_USB_START,
187 	BOOTSTAGE_ID_ETH_START,
188 	BOOTSTAGE_ID_BOOTP_START,
189 	BOOTSTAGE_ID_BOOTP_STOP,
190 	BOOTSTAGE_ID_BOOTM_START,
191 	BOOTSTAGE_ID_BOOTM_HANDOFF,
192 	BOOTSTAGE_ID_MAIN_LOOP,
193 	BOOTSTAGE_KERNELREAD_START,
194 	BOOTSTAGE_KERNELREAD_STOP,
195 
196 	BOOTSTAGE_ID_CPU_AWAKE,
197 	BOOTSTAGE_ID_MAIN_CPU_AWAKE,
198 	BOOTSTAGE_ID_MAIN_CPU_READY,
199 
200 	/* a few spare for the user, from here */
201 	BOOTSTAGE_ID_USER,
202 	BOOTSTAGE_ID_COUNT = BOOTSTAGE_ID_USER + CONFIG_BOOTSTAGE_USER_COUNT,
203 	BOOTSTAGE_ID_ALLOC,
204 };
205 
206 /*
207  * Return the time since boot in microseconds, This is needed for bootstage
208  * and should be defined in CPU- or board-specific code. If undefined then
209  * millisecond resolution will be used (the standard get_timer()).
210  */
211 ulong timer_get_boot_us(void);
212 
213 #ifndef CONFIG_SPL_BUILD
214 /*
215  * Board code can implement show_boot_progress() if needed.
216  *
217  * @param val	Progress state (enum bootstage_id), or -id if an error
218  *		has occurred.
219  */
220 void show_boot_progress(int val);
221 #else
222 #define show_boot_progress(val) do {} while (0)
223 #endif
224 
225 #if defined(CONFIG_BOOTSTAGE) && !defined(CONFIG_SPL_BUILD)
226 /* This is the full bootstage implementation */
227 
228 /*
229  * Mark a time stamp for the current boot stage.
230  */
231 ulong bootstage_mark(enum bootstage_id id);
232 
233 ulong bootstage_error(enum bootstage_id id);
234 
235 ulong bootstage_mark_name(enum bootstage_id id, const char *name);
236 
237 /* Print a report about boot time */
238 void bootstage_report(void);
239 
240 #else
241 /*
242  * This is a dummy implementation which just calls show_boot_progress(),
243  * and won't even do that unless CONFIG_SHOW_BOOT_PROGRESS is defined
244  */
245 
246 static inline ulong bootstage_mark(enum bootstage_id id)
247 {
248 	show_boot_progress(id);
249 	return 0;
250 }
251 
252 static inline ulong bootstage_error(enum bootstage_id id)
253 {
254 	show_boot_progress(-id);
255 	return 0;
256 }
257 
258 static inline ulong bootstage_mark_name(enum bootstage_id id, const char *name)
259 {
260 	return 0;
261 }
262 
263 
264 #endif /* CONFIG_BOOTSTAGE */
265 
266 #endif
267