summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Setje-Eilers <jan.setjeeilers@oracle.com>2024-07-12 17:07:45 -0700
committerPeter Jones <pjones@redhat.com>2025-02-18 10:21:19 -0500
commit2b49dc13aed3723c7c841c2788217ff7b0e821df (patch)
treee064ba50dd2994343a835767e5038cdab6d51474
parentc57af36e673b34a9b24309f76f105371316c45be (diff)
downloadefi-boot-shim-2b49dc13aed3723c7c841c2788217ff7b0e821df.tar.gz
efi-boot-shim-2b49dc13aed3723c7c841c2788217ff7b0e821df.zip
Suppress file open failures for some netboot cases
Reading files during a netboot comes with the caveat that fetching files from a network does not support anything like listing a directory. In the past this has meant that we do not try to open optional files during a netboot. However at least the revocation.efi file is now tested during a netboot, which will print an error when it is not found. Since that error is spurious we should allow for those errors to be suppressed. This is also desirable since we will likely go looking for additional files in the near future. Signed-off-by: Jan Setje-Eilers <Jan.SetjeEilers@oracle.com>
-rw-r--r--include/netboot.h5
-rw-r--r--netboot.c13
-rw-r--r--shim.c23
3 files changed, 27 insertions, 14 deletions
diff --git a/include/netboot.h b/include/netboot.h
index a7bf6cd8..296f10f0 100644
--- a/include/netboot.h
+++ b/include/netboot.h
@@ -3,10 +3,13 @@
#ifndef SHIM_NETBOOT_H
#define SHIM_NETBOOT_H
+#define SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE 1
+
extern BOOLEAN findNetboot(EFI_HANDLE image_handle);
extern EFI_STATUS parseNetbootinfo(EFI_HANDLE image_handle, CHAR8 *name);
-extern EFI_STATUS FetchNetbootimage(EFI_HANDLE image_handle, VOID **buffer, UINT64 *bufsiz);
+extern EFI_STATUS FetchNetbootimage(EFI_HANDLE image_handle, VOID **buffer,
+ UINT64 *bufsiz, int flags);
#endif /* SHIM_NETBOOT_H */
diff --git a/netboot.c b/netboot.c
index a4cc7acd..46765427 100644
--- a/netboot.c
+++ b/netboot.c
@@ -368,7 +368,8 @@ status_from_error(UINT8 error_code)
}
}
-EFI_STATUS FetchNetbootimage(EFI_HANDLE image_handle UNUSED, VOID **buffer, UINT64 *bufsiz)
+EFI_STATUS FetchNetbootimage(EFI_HANDLE image_handle UNUSED, VOID **buffer,
+ UINT64 *bufsiz, int flags)
{
EFI_STATUS efi_status;
EFI_PXE_BASE_CODE_TFTP_OPCODE read = EFI_PXE_BASE_CODE_TFTP_READ_FILE;
@@ -376,7 +377,8 @@ EFI_STATUS FetchNetbootimage(EFI_HANDLE image_handle UNUSED, VOID **buffer, UINT
BOOLEAN nobuffer = FALSE;
UINTN blksz = 512;
- console_print(L"Fetching Netboot Image %a\n", full_path);
+ if (~flags & SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE)
+ console_print(L"Fetching Netboot Image %a\n", full_path);
if (*buffer == NULL) {
*buffer = AllocatePool(4096 * 1024);
if (!*buffer)
@@ -399,7 +401,8 @@ try_again:
if (EFI_ERROR(efi_status)) {
if (pxe->Mode->TftpErrorReceived) {
- console_print(L"TFTP error %u: %a\n",
+ if (~flags & SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE)
+ console_print(L"TFTP error %u: %a\n",
pxe->Mode->TftpError.ErrorCode,
pxe->Mode->TftpError.ErrorString);
@@ -412,7 +415,9 @@ try_again:
*
* https://github.com/tianocore/edk2/pull/6287
*/
- console_print(L"Unknown TFTP error, treating as file not found\n");
+ if (~flags & SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE)
+ console_print(L"Unknown TFTP error, treating "
+ "as file not found\n");
efi_status = EFI_NOT_FOUND;
}
diff --git a/shim.c b/shim.c
index bf0c9e6c..d040992d 100644
--- a/shim.c
+++ b/shim.c
@@ -1055,7 +1055,8 @@ str16_to_str8(CHAR16 *str16, CHAR8 **str8)
* Load and run an EFI executable
*/
EFI_STATUS read_image(EFI_HANDLE image_handle, CHAR16 *ImagePath,
- CHAR16 **PathName, void **data, int *datasize)
+ CHAR16 **PathName, void **data, int *datasize,
+ int flags)
{
EFI_STATUS efi_status;
void *sourcebuffer = NULL;
@@ -1092,10 +1093,11 @@ EFI_STATUS read_image(EFI_HANDLE image_handle, CHAR16 *ImagePath,
}
FreePool(netbootname);
efi_status = FetchNetbootimage(image_handle, &sourcebuffer,
- &sourcesize);
+ &sourcesize, flags);
if (EFI_ERROR(efi_status)) {
- perror(L"Unable to fetch TFTP image: %r\n",
- efi_status);
+ if (~flags & SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE)
+ perror(L"Unable to fetch TFTP image: %r\n",
+ efi_status);
return efi_status;
}
*data = sourcebuffer;
@@ -1107,8 +1109,9 @@ EFI_STATUS read_image(EFI_HANDLE image_handle, CHAR16 *ImagePath,
&sourcesize,
netbootname);
if (EFI_ERROR(efi_status)) {
- perror(L"Unable to fetch HTTP image %a: %r\n",
- netbootname, efi_status);
+ if (~flags & SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE)
+ perror(L"Unable to fetch HTTP image %a: %r\n",
+ netbootname, efi_status);
return efi_status;
}
*data = sourcebuffer;
@@ -1147,7 +1150,7 @@ EFI_STATUS start_image(EFI_HANDLE image_handle, CHAR16 *ImagePath)
int datasize = 0;
efi_status = read_image(image_handle, ImagePath, &PathName, &data,
- &datasize);
+ &datasize, 0);
if (EFI_ERROR(efi_status))
goto done;
@@ -1435,7 +1438,8 @@ load_revocations_file(EFI_HANDLE image_handle, CHAR16 *PathName)
uint8_t *sspv_latest = NULL;
efi_status = read_image(image_handle, L"revocations.efi", &PathName,
- &data, &datasize);
+ &data, &datasize,
+ SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE);
if (EFI_ERROR(efi_status))
return efi_status;
@@ -1499,7 +1503,8 @@ load_cert_file(EFI_HANDLE image_handle, CHAR16 *filename, CHAR16 *PathName)
int i;
efi_status = read_image(image_handle, filename, &PathName,
- &data, &datasize);
+ &data, &datasize,
+ SUPPRESS_NETBOOT_OPEN_FAILURE_NOISE);
if (EFI_ERROR(efi_status))
return efi_status;