8 * Return status codes as used within gPXE are designed to allow for
9 * maximum visibility into the source of an error even in an end-user
10 * build with no debugging. They are constructed as follows:
12 * Bits 7-0 : PXE error code
14 * This is the closest equivalent PXE error code
15 * (e.g. PXENV_STATUS_OUT_OF_RESOURCES), and is the only part of the
16 * error that will be returned via the PXE API, since PXE has
17 * predefined error codes.
19 * Bits 12-8 : Per-file disambiguator
21 * When the same error number can be generated from multiple points
22 * within a file, this field can be used to identify the unique
25 * Bits 23-13 : File identifier
27 * This is a unique identifier for the file generating the error
28 * (e.g. ERRFILE_tcp for tcp.c).
30 * Bits 30-24 : POSIX error code
32 * This is the closest equivalent POSIX error code (e.g. ENOMEM).
36 * Errors are usually return as negative error numbers (e.g. -EINVAL);
37 * bit 31 is therefore unusable.
40 * The convention within the code is that errors are negative and
41 * expressed using the POSIX error code and (optionally) a per-file
48 * #define ETCP_BAD_CHECKSUM EUNIQ_02
49 * return -( EINVAL | ETCP_BAD_CHECKSUM )
51 * By various bits of preprocessor magic, the PXE error code and file
52 * identifier are already incorporated into the definition of the
53 * POSIX error code, which keeps the code relatively clean.
56 * Functions that wish to return failures should be declared as
57 * returning an integer @c rc "Return status code". A return value of
58 * zero indicates success, a non-zero value indicates failure. The
59 * return value can be passed directly to strerror() in order to
60 * generate a human-readable error message, e.g.
62 * if ( ( rc = some_function ( ... ) ) != 0 ) {
63 * DBG ( "Whatever I was trying to do failed: %s\n", strerror ( rc ) );
67 * As illustrated in the above example, error returns should generally
68 * be directly propagated upward to the calling function.
72 /* Get definitions for file identifiers */
73 #include <gpxe/errfile.h>
75 /* If we do not have a valid file identifier, generate a compiler
76 * warning upon usage of any error codes. (Don't just use a #warning,
77 * because some files include errno.h but don't ever actually use any
81 extern char missing_errfile_declaration
[] __attribute__ (( deprecated
));
83 #define ERRFILE ( 0 * ( ( int ) missing_errfile_declaration ) )
86 /** Derive PXENV_STATUS code from gPXE error number */
87 #define PXENV_STATUS( rc ) ( (-(rc)) & 0x00ff )
90 * @defgroup pxeerrors PXE error codes
92 * The names, meanings and values of these error codes are defined by
93 * the PXE specification.
99 #define PXENV_STATUS_SUCCESS 0x0000
100 #define PXENV_STATUS_FAILURE 0x0001
101 #define PXENV_STATUS_BAD_FUNC 0x0002
102 #define PXENV_STATUS_UNSUPPORTED 0x0003
103 #define PXENV_STATUS_KEEP_UNDI 0x0004
104 #define PXENV_STATUS_KEEP_ALL 0x0005
105 #define PXENV_STATUS_OUT_OF_RESOURCES 0x0006
107 /* ARP errors (0x0010 to 0x001f) */
108 #define PXENV_STATUS_ARP_TIMEOUT 0x0011
110 /* Base-Code state errors */
111 #define PXENV_STATUS_UDP_CLOSED 0x0018
112 #define PXENV_STATUS_UDP_OPEN 0x0019
113 #define PXENV_STATUS_TFTP_CLOSED 0x001a
114 #define PXENV_STATUS_TFTP_OPEN 0x001b
116 /* BIOS/system errors (0x0020 to 0x002f) */
117 #define PXENV_STATUS_MCOPY_PROBLEM 0x0020
118 #define PXENV_STATUS_BIS_INTEGRITY_FAILURE 0x0021
119 #define PXENV_STATUS_BIS_VALIDATE_FAILURE 0x0022
120 #define PXENV_STATUS_BIS_INIT_FAILURE 0x0023
121 #define PXENV_STATUS_BIS_SHUTDOWN_FAILURE 0x0024
122 #define PXENV_STATUS_BIS_GBOA_FAILURE 0x0025
123 #define PXENV_STATUS_BIS_FREE_FAILURE 0x0026
124 #define PXENV_STATUS_BIS_GSI_FAILURE 0x0027
125 #define PXENV_STATUS_BIS_BAD_CKSUM 0x0028
127 /* TFTP/MTFTP errors (0x0030 to 0x003f) */
128 #define PXENV_STATUS_TFTP_CANNOT_ARP_ADDRESS 0x0030
129 #define PXENV_STATUS_TFTP_OPEN_TIMEOUT 0x0032
130 #define PXENV_STATUS_TFTP_UNKNOWN_OPCODE 0x0033
131 #define PXENV_STATUS_TFTP_READ_TIMEOUT 0x0035
132 #define PXENV_STATUS_TFTP_ERROR_OPCODE 0x0036
133 #define PXENV_STATUS_TFTP_CANNOT_OPEN_CONNECTION 0x0038
134 #define PXENV_STATUS_TFTP_CANNOT_READ_FROM_CONNECTION 0x0039
135 #define PXENV_STATUS_TFTP_TOO_MANY_PACKAGES 0x003a
136 #define PXENV_STATUS_TFTP_FILE_NOT_FOUND 0x003b
137 #define PXENV_STATUS_TFTP_ACCESS_VIOLATION 0x003c
138 #define PXENV_STATUS_TFTP_NO_MCAST_ADDRESS 0x003d
139 #define PXENV_STATUS_TFTP_NO_FILESIZE 0x003e
140 #define PXENV_STATUS_TFTP_INVALID_PACKET_SIZE 0x003f
142 /* Reserved errors 0x0040 to 0x004f) */
144 /* DHCP/BOOTP errors (0x0050 to 0x005f) */
145 #define PXENV_STATUS_DHCP_TIMEOUT 0x0051
146 #define PXENV_STATUS_DHCP_NO_IP_ADDRESS 0x0052
147 #define PXENV_STATUS_DHCP_NO_BOOTFILE_NAME 0x0053
148 #define PXENV_STATUS_DHCP_BAD_IP_ADDRESS 0x0054
150 /* Driver errors (0x0060 to 0x006f) */
151 #define PXENV_STATUS_UNDI_INVALID_FUNCTION 0x0060
152 #define PXENV_STATUS_UNDI_MEDIATEST_FAILED 0x0061
153 #define PXENV_STATUS_UNDI_CANNOT_INIT_NIC_FOR_MCAST 0x0062
154 #define PXENV_STATUS_UNDI_CANNOT_INITIALIZE_NIC 0x0063
155 #define PXENV_STATUS_UNDI_CANNOT_INITIALIZE_PHY 0x0064
156 #define PXENV_STATUS_UNDI_CANNOT_READ_CONFIG_DATA 0x0065
157 #define PXENV_STATUS_UNDI_CANNOT_READ_INIT_DATA 0x0066
158 #define PXENV_STATUS_UNDI_BAD_MAC_ADDRESS 0x0067
159 #define PXENV_STATUS_UNDI_BAD_EEPROM_CHECKSUM 0x0068
160 #define PXENV_STATUS_UNDI_ERROR_SETTING_ISR 0x0069
161 #define PXENV_STATUS_UNDI_INVALID_STATE 0x006a
162 #define PXENV_STATUS_UNDI_TRANSMIT_ERROR 0x006b
163 #define PXENV_STATUS_UNDI_INVALID_PARAMETER 0x006c
165 /* ROM and NBP bootstrap errors (0x0070 to 0x007f) */
166 #define PXENV_STATUS_BSTRAP_PROMPT_MENU 0x0074
167 #define PXENV_STATUS_BSTRAP_MCAST_ADDR 0x0076
168 #define PXENV_STATUS_BSTRAP_MISSING_LIST 0x0077
169 #define PXENV_STATUS_BSTRAP_NO_RESPONSE 0x0078
170 #define PXENV_STATUS_BSTRAP_FILE_TOO_BIG 0x0079
172 /* Environment NBP errors (0x0080 to 0x008f) */
174 /* Reserved errors (0x0090 to 0x009f) */
176 /* Miscellaneous errors (0x00a0 to 0x00af) */
177 #define PXENV_STATUS_BINL_CANCELED_BY_KEYSTROKE 0x00a0
178 #define PXENV_STATUS_BINL_NO_PXE_SERVER 0x00a1
179 #define PXENV_STATUS_NOT_AVAILABLE_IN_PMODE 0x00a2
180 #define PXENV_STATUS_NOT_AVAILABLE_IN_RMODE 0x00a3
182 /* BUSD errors (0x00b0 to 0x00bf) */
183 #define PXENV_STATUS_BUSD_DEVICE_NOT_SUPPORTED 0x00b0
185 /* Loader errors (0x00c0 to 0x00cf) */
186 #define PXENV_STATUS_LOADER_NO_FREE_BASE_MEMORY 0x00c0
187 #define PXENV_STATUS_LOADER_NO_BC_ROMID 0x00c1
188 #define PXENV_STATUS_LOADER_BAD_BC_ROMID 0x00c2
189 #define PXENV_STATUS_LOADER_BAD_BC_RUNTIME_IMAGE 0x00c3
190 #define PXENV_STATUS_LOADER_NO_UNDI_ROMID 0x00c4
191 #define PXENV_STATUS_LOADER_BAD_UNDI_ROMID 0x00c5
192 #define PXENV_STATUS_LOADER_BAD_UNDI_DRIVER_IMAGE 0x00c6
193 #define PXENV_STATUS_LOADER_NO_PXE_STRUCT 0x00c8
194 #define PXENV_STATUS_LOADER_NO_PXENV_STRUCT 0x00c9
195 #define PXENV_STATUS_LOADER_UNDI_START 0x00ca
196 #define PXENV_STATUS_LOADER_BC_START 0x00cb
201 * @defgroup posixerrors POSIX error codes
203 * The names and meanings (but not the values) of these error codes
204 * are defined by POSIX. We choose to assign unique values which
205 * incorporate the closest equivalent PXE error code, so that code may
206 * simply use ENOMEM, rather than having to use the cumbersome
207 * (ENOMEM|PXENV_STATUS_OUT_OF_RESOURCES).
212 /** Operation completed successfully */
213 #define ENOERR ( ERRFILE | PXENV_STATUS_SUCCESS | 0x00000000 )
215 /** Arg list too long */
216 #define E2BIG ( ERRFILE | PXENV_STATUS_BAD_FUNC | 0x01000000 )
218 /** Permission denied */
219 #define EACCES ( ERRFILE | PXENV_STATUS_TFTP_ACCESS_VIOLATION | 0x02000000 )
221 /** Address in use */
222 #define EADDRINUSE ( ERRFILE | PXENV_STATUS_UDP_OPEN | 0x03000000 )
224 /** Address not available */
225 #define EADDRNOTAVAIL ( ERRFILE | PXENV_STATUS_UDP_OPEN | 0x04000000 )
227 /** Address family not supported */
228 #define EAFNOSUPPORT ( ERRFILE | PXENV_STATUS_UNSUPPORTED | 0x05000000 )
230 /** Resource temporarily unavailable */
231 #define EAGAIN ( ERRFILE | PXENV_STATUS_FAILURE | 0x06000000 )
233 /** Connection already in progress */
234 #define EALREADY ( ERRFILE | PXENV_STATUS_UDP_OPEN | 0x07000000 )
236 /** Bad file descriptor */
237 #define EBADF ( ERRFILE | PXENV_STATUS_TFTP_CLOSED | 0x08000000 )
240 #define EBADMSG ( ERRFILE | PXENV_STATUS_FAILURE | 0x09000000 )
243 #define EBUSY ( ERRFILE | PXENV_STATUS_OUT_OF_RESOURCES | 0x0a000000 )
245 /** Operation canceled */
247 ( ERRFILE | PXENV_STATUS_BINL_CANCELED_BY_KEYSTROKE | 0x0b000000 )
249 /** No child processes */
250 #define ECHILD ( ERRFILE | PXENV_STATUS_TFTP_FILE_NOT_FOUND | 0x0c000000 )
252 /** Connection aborted */
253 #define ECONNABORTED \
254 ( ERRFILE | PXENV_STATUS_TFTP_CANNOT_READ_FROM_CONNECTION | 0x0d000000 )
256 /** Connection refused */
257 #define ECONNREFUSED \
258 ( ERRFILE | PXENV_STATUS_TFTP_CANNOT_OPEN_CONNECTION | 0x0e000000 )
260 /** Connection reset */
262 ( ERRFILE | PXENV_STATUS_TFTP_CANNOT_READ_FROM_CONNECTION | 0x0f000000 )
264 /** Resource deadlock avoided */
265 #define EDEADLK ( ERRFILE | PXENV_STATUS_FAILURE | 0x10000000 )
267 /** Destination address required */
268 #define EDESTADDRREQ ( ERRFILE | PXENV_STATUS_BAD_FUNC | 0x11000000 )
271 #define EDOM ( ERRFILE | PXENV_STATUS_FAILURE | 0x12000000 )
274 #define EDQUOT ( ERRFILE | PXENV_STATUS_FAILURE | 0x13000000 )
277 #define EEXIST ( ERRFILE | PXENV_STATUS_FAILURE | 0x14000000 )
280 #define EFAULT ( ERRFILE | PXENV_STATUS_MCOPY_PROBLEM | 0x15000000 )
282 /** File too large */
283 #define EFBIG ( ERRFILE | PXENV_STATUS_MCOPY_PROBLEM | 0x16000000 )
285 /** Host is unreachable */
286 #define EHOSTUNREACH ( ERRFILE | PXENV_STATUS_ARP_TIMEOUT | 0x17000000 )
288 /** Identifier removed */
289 #define EIDRM ( ERRFILE | PXENV_STATUS_FAILURE | 0x18000000 )
291 /** Illegal byte sequence */
292 #define EILSEQ ( ERRFILE | PXENV_STATUS_FAILURE | 0x19000000 )
294 /** Operation in progress */
295 #define EINPROGRESS ( ERRFILE | PXENV_STATUS_FAILURE | 0x1a000000 )
297 /** Interrupted function call */
298 #define EINTR ( ERRFILE | PXENV_STATUS_FAILURE | 0x1b000000 )
300 /** Invalid argument */
301 #define EINVAL ( ERRFILE | PXENV_STATUS_BAD_FUNC | 0x1c000000 )
303 /** Input/output error */
305 ( ERRFILE | PXENV_STATUS_TFTP_CANNOT_READ_FROM_CONNECTION | 0x1d000000 )
307 /** Socket is connected */
308 #define EISCONN ( ERRFILE | PXENV_STATUS_UDP_OPEN | 0x1e000000 )
310 /** Is a directory */
311 #define EISDIR ( ERRFILE | PXENV_STATUS_FAILURE | 0x1f000000 )
313 /** Too many levels of symbolic links */
314 #define ELOOP ( ERRFILE | PXENV_STATUS_FAILURE | 0x20000000 )
316 /** Too many open files */
317 #define EMFILE ( ERRFILE | PXENV_STATUS_OUT_OF_RESOURCES | 0x21000000 )
319 /** Too many links */
320 #define EMLINK ( ERRFILE | PXENV_STATUS_FAILURE | 0x22000000 )
322 /** Inappropriate message buffer length */
323 #define EMSGSIZE ( ERRFILE | PXENV_STATUS_BAD_FUNC | 0x23000000 )
326 #define EMULTIHOP ( ERRFILE | PXENV_STATUS_FAILURE | 0x24000000 )
328 /** Filename too long */
329 #define ENAMETOOLONG ( ERRFILE | PXENV_STATUS_FAILURE | 0x25000000 )
331 /** Network is down */
332 #define ENETDOWN ( ERRFILE | PXENV_STATUS_ARP_TIMEOUT | 0x26000000 )
334 /** Connection aborted by network */
335 #define ENETRESET ( ERRFILE | PXENV_STATUS_FAILURE | 0x27000000 )
337 /** Network unreachable */
338 #define ENETUNREACH ( ERRFILE | PXENV_STATUS_ARP_TIMEOUT | 0x28000000 )
340 /** Too many open files in system */
341 #define ENFILE ( ERRFILE | PXENV_STATUS_OUT_OF_RESOURCES | 0x29000000 )
343 /** No buffer space available */
344 #define ENOBUFS ( ERRFILE | PXENV_STATUS_OUT_OF_RESOURCES | 0x2a000000 )
346 /** No message is available on the STREAM head read queue */
347 #define ENODATA ( ERRFILE | PXENV_STATUS_FAILURE | 0x2b000000 )
349 /** No such device */
350 #define ENODEV ( ERRFILE | PXENV_STATUS_TFTP_FILE_NOT_FOUND | 0x2c000000 )
352 /** No such file or directory */
353 #define ENOENT ( ERRFILE | PXENV_STATUS_TFTP_FILE_NOT_FOUND | 0x2d000000 )
355 /** Exec format error */
356 #define ENOEXEC ( ERRFILE | PXENV_STATUS_FAILURE | 0x2e000000 )
358 /** No locks available */
359 #define ENOLCK ( ERRFILE | PXENV_STATUS_FAILURE | 0x2f000000 )
362 #define ENOLINK ( ERRFILE | PXENV_STATUS_FAILURE | 0x30000000 )
364 /** Not enough space */
365 #define ENOMEM ( ERRFILE | PXENV_STATUS_OUT_OF_RESOURCES | 0x31000000 )
367 /** No message of the desired type */
368 #define ENOMSG ( ERRFILE | PXENV_STATUS_FAILURE | 0x32000000 )
370 /** Protocol not available */
371 #define ENOPROTOOPT ( ERRFILE | PXENV_STATUS_UNSUPPORTED | 0x33000000 )
373 /** No space left on device */
374 #define ENOSPC ( ERRFILE | PXENV_STATUS_OUT_OF_RESOURCES | 0x34000000 )
376 /** No STREAM resources */
377 #define ENOSR ( ERRFILE | PXENV_STATUS_OUT_OF_RESOURCES | 0x35000000 )
380 #define ENOSTR ( ERRFILE | PXENV_STATUS_FAILURE | 0x36000000 )
382 /** Function not implemented */
383 #define ENOSYS ( ERRFILE | PXENV_STATUS_UNSUPPORTED | 0x37000000 )
385 /** The socket is not connected */
386 #define ENOTCONN ( ERRFILE | PXENV_STATUS_FAILURE | 0x38000000 )
388 /** Not a directory */
389 #define ENOTDIR ( ERRFILE | PXENV_STATUS_FAILURE | 0x39000000 )
391 /** Directory not empty */
392 #define ENOTEMPTY ( ERRFILE | PXENV_STATUS_FAILURE | 0x3a000000 )
395 #define ENOTSOCK ( ERRFILE | PXENV_STATUS_FAILURE | 0x3b000000 )
398 #define ENOTSUP ( ERRFILE | PXENV_STATUS_UNSUPPORTED | 0x3c000000 )
400 /** Inappropriate I/O control operation */
401 #define ENOTTY ( ERRFILE | PXENV_STATUS_FAILURE | 0x3d000000 )
403 /** No such device or address */
404 #define ENXIO ( ERRFILE | PXENV_STATUS_TFTP_FILE_NOT_FOUND | 0x3e000000 )
406 /** Operation not supported on socket */
407 #define EOPNOTSUPP ( ERRFILE | PXENV_STATUS_UNSUPPORTED | 0x3f000000 )
409 /** Value too large to be stored in data type */
410 #define EOVERFLOW ( ERRFILE | PXENV_STATUS_FAILURE | 0x40000000 )
412 /** Operation not permitted */
413 #define EPERM ( ERRFILE | PXENV_STATUS_TFTP_ACCESS_VIOLATION | 0x41000000 )
416 #define EPIPE ( ERRFILE | PXENV_STATUS_FAILURE | 0x42000000 )
418 /** Protocol error */
419 #define EPROTO ( ERRFILE | PXENV_STATUS_FAILURE | 0x43000000 )
421 /** Protocol not supported */
422 #define EPROTONOSUPPORT ( ERRFILE | PXENV_STATUS_UNSUPPORTED | 0x44000000 )
424 /** Protocol wrong type for socket */
425 #define EPROTOTYPE ( ERRFILE | PXENV_STATUS_FAILURE | 0x45000000 )
427 /** Result too large */
428 #define ERANGE ( ERRFILE | PXENV_STATUS_FAILURE | 0x46000000 )
430 /** Read-only file system */
431 #define EROFS ( ERRFILE | PXENV_STATUS_FAILURE | 0x47000000 )
434 #define ESPIPE ( ERRFILE | PXENV_STATUS_FAILURE | 0x48000000 )
436 /** No such process */
437 #define ESRCH ( ERRFILE | PXENV_STATUS_TFTP_FILE_NOT_FOUND | 0x49000000 )
439 /** Stale file handle */
440 #define ESTALE ( ERRFILE | PXENV_STATUS_FAILURE | 0x4a000000 )
442 /** STREAM ioctl() timeout */
443 #define ETIME ( ERRFILE | PXENV_STATUS_FAILURE | 0x4b000000 )
445 /** Operation timed out */
446 #define ETIMEDOUT ( ERRFILE | PXENV_STATUS_TFTP_READ_TIMEOUT | 0x4c000000 )
448 /** Text file busy */
449 #define ETXTBSY ( ERRFILE | PXENV_STATUS_FAILURE | 0x4d000000 )
451 /** Operation would block (different from EAGAIN!) */
452 #define EWOULDBLOCK ( ERRFILE | PXENV_STATUS_TFTP_OPEN | 0x4e000000 )
455 #define EXDEV ( ERRFILE | PXENV_STATUS_FAILURE | 0x4f000000 )
460 * @defgroup euniq Per-file error disambiguators
462 * Files which use the same error number multiple times should
463 * probably define their own error subspace using these
464 * disambiguators. For example:
466 * #define ETCP_HEADER_TOO_SHORT EUNIQ_01
467 * #define ETCP_BAD_CHECKSUM EUNIQ_02
472 #define EUNIQ_01 0x00000100
473 #define EUNIQ_02 0x00000200
474 #define EUNIQ_03 0x00000300
475 #define EUNIQ_04 0x00000400
476 #define EUNIQ_05 0x00000500
477 #define EUNIQ_06 0x00000600
478 #define EUNIQ_07 0x00000700
479 #define EUNIQ_08 0x00000800
480 #define EUNIQ_09 0x00000900
481 #define EUNIQ_0A 0x00000a00
482 #define EUNIQ_0B 0x00000b00
483 #define EUNIQ_0C 0x00000c00
484 #define EUNIQ_0D 0x00000d00
485 #define EUNIQ_0E 0x00000e00
486 #define EUNIQ_0F 0x00000f00
487 #define EUNIQ_10 0x00001000
488 #define EUNIQ_11 0x00001100
489 #define EUNIQ_12 0x00001200
490 #define EUNIQ_13 0x00001300
491 #define EUNIQ_14 0x00001400
492 #define EUNIQ_15 0x00001500
493 #define EUNIQ_16 0x00001600
494 #define EUNIQ_17 0x00001700
495 #define EUNIQ_18 0x00001800
496 #define EUNIQ_19 0x00001900
497 #define EUNIQ_1A 0x00001a00
498 #define EUNIQ_1B 0x00001b00
499 #define EUNIQ_1C 0x00001c00
500 #define EUNIQ_1D 0x00001d00
501 #define EUNIQ_1E 0x00001e00
502 #define EUNIQ_1F 0x00001f00