|
16 | 16 | #define ntohs(x) __builtin_bswap16(x) /* supported both by GCC and clang */
|
17 | 17 | #define htons(x) ntohs(x)
|
18 | 18 |
|
| 19 | +/* TFTP error codes from RFC 1350 */ |
| 20 | +#define TFTP_ERROR_NOT_DEFINED 0 /* Not defined, see error message (if any). */ |
| 21 | +#define TFTP_ERROR_NOT_FOUND 1 /* File not found. */ |
| 22 | +#define TFTP_ERROR_ACCESS 2 /* Access violation. */ |
| 23 | +#define TFTP_ERROR_NO_SPACE 3 /* Disk full or allocation exceeded. */ |
| 24 | +#define TFTP_ERROR_ILLEGAL_OP 4 /* Illegal TFTP operation. */ |
| 25 | +#define TFTP_ERROR_UNKNOWN_ID 5 /* Unknown transfer ID. */ |
| 26 | +#define TFTP_ERROR_EXISTS 6 /* File already exists. */ |
| 27 | +#define TFTP_ERROR_NO_USER 7 /* No such user. */ |
| 28 | + |
19 | 29 | static EFI_PXE_BASE_CODE *pxe;
|
20 | 30 | static EFI_IP_ADDRESS tftp_addr;
|
21 | 31 | static CHAR8 *full_path;
|
@@ -362,8 +372,34 @@ EFI_STATUS FetchNetbootimage(EFI_HANDLE image_handle UNUSED, VOID **buffer, UINT
|
362 | 372 | goto try_again;
|
363 | 373 | }
|
364 | 374 |
|
365 |
| - if (EFI_ERROR(efi_status) && *buffer) { |
366 |
| - FreePool(*buffer); |
| 375 | + if (EFI_ERROR(efi_status)) { |
| 376 | + if (pxe->Mode->TftpErrorReceived) { |
| 377 | + console_print(L"TFTP error %u: %a\n", |
| 378 | + pxe->Mode->TftpError.ErrorCode, |
| 379 | + pxe->Mode->TftpError.ErrorString); |
| 380 | + |
| 381 | + switch (pxe->Mode->TftpError.ErrorCode) { |
| 382 | + case TFTP_ERROR_NOT_FOUND: |
| 383 | + efi_status = EFI_NOT_FOUND; |
| 384 | + break; |
| 385 | + default: |
| 386 | + break; |
| 387 | + } |
| 388 | + } else if (efi_status == EFI_TFTP_ERROR) { |
| 389 | + /* |
| 390 | + * Unfortunately, some firmware doesn't fill in the |
| 391 | + * error details. Treat all TFTP errors like file not |
| 392 | + * found so shim falls back to the default loader. |
| 393 | + * |
| 394 | + * https://github.com/tianocore/edk2/pull/6287 |
| 395 | + */ |
| 396 | + console_print(L"Unknown TFTP error, treating as file not found\n"); |
| 397 | + efi_status = EFI_NOT_FOUND; |
| 398 | + } |
| 399 | + |
| 400 | + if (*buffer) { |
| 401 | + FreePool(*buffer); |
| 402 | + } |
367 | 403 | }
|
368 | 404 | return efi_status;
|
369 | 405 | }
|
0 commit comments