* Copyright (c) 2016 Alexander Graf
*/
+#define LOG_CATEGORY LOGC_EFI
+
#include <common.h>
#include <cpu_func.h>
#include <efi_loader.h>
+#include <log.h>
#include <malloc.h>
#include <pe.h>
#include <sort.h>
case IMAGE_REL_BASED_RISCV_LOW12S:
/* We know that we're 4k aligned */
if (delta & 0xfff) {
- printf("Unsupported reloc offset\n");
+ log_err("Unsupported reloc offset\n");
return EFI_LOAD_ERROR;
}
break;
#endif
default:
- printf("Unknown Relocation off %x type %x\n",
- offset, type);
+ log_err("Unknown Relocation off %x type %x\n",
+ offset, type);
return EFI_LOAD_ERROR;
}
relocs++;
loaded_image_info->image_data_type = EFI_RUNTIME_SERVICES_DATA;
break;
default:
- printf("%s: invalid image type: %u\n", __func__, image_type);
+ log_err("invalid image type: %u\n", image_type);
/* Let's assume it is an application */
loaded_image_info->image_code_type = EFI_LOADER_CODE;
loaded_image_info->image_data_type = EFI_LOADER_DATA;
size_t new_efi_size, auth_size;
bool ret = false;
- debug("%s: Enter, %d\n", __func__, ret);
+ EFI_PRINT("%s: Enter, %d\n", __func__, ret);
if (!efi_secure_boot_enabled())
return true;
break;
}
- debug("Signature was not verified by \"db\"\n");
+ EFI_PRINT("Signature was not verified by \"db\"\n");
if (efi_signature_lookup_digest(regs, db)) {
ret = true;
break;
}
- debug("Image's digest was not found in \"db\" or \"dbx\"\n");
+ EFI_PRINT("Image's digest was not found in \"db\" or \"dbx\"\n");
}
err:
free(regs);
free(new_efi);
- debug("%s: Exit, %d\n", __func__, ret);
+ EFI_PRINT("%s: Exit, %d\n", __func__, ret);
return ret;
}
#else
/* Sanity check for a file header */
if (efi_size < sizeof(*dos)) {
- printf("%s: Truncated DOS Header\n", __func__);
+ log_err("Truncated DOS Header\n");
ret = EFI_LOAD_ERROR;
goto err;
}
dos = efi;
if (dos->e_magic != IMAGE_DOS_SIGNATURE) {
- printf("%s: Invalid DOS Signature\n", __func__);
+ log_err("Invalid DOS Signature\n");
ret = EFI_LOAD_ERROR;
goto err;
}
* of the 64bit header which is longer than the 32bit header.
*/
if (efi_size < dos->e_lfanew + sizeof(IMAGE_NT_HEADERS64)) {
- printf("%s: Invalid offset for Extended Header\n", __func__);
+ log_err("Invalid offset for Extended Header\n");
ret = EFI_LOAD_ERROR;
goto err;
}
nt = (void *) ((char *)efi + dos->e_lfanew);
if (nt->Signature != IMAGE_NT_SIGNATURE) {
- printf("%s: Invalid NT Signature\n", __func__);
+ log_err("Invalid NT Signature\n");
ret = EFI_LOAD_ERROR;
goto err;
}
}
if (!supported) {
- printf("%s: Machine type 0x%04x is not supported\n",
- __func__, nt->FileHeader.Machine);
+ log_err("Machine type 0x%04x is not supported\n",
+ nt->FileHeader.Machine);
ret = EFI_LOAD_ERROR;
goto err;
}
if (efi_size < ((void *)sections + sizeof(sections[0]) * num_sections
- efi)) {
- printf("%s: Invalid number of sections: %d\n",
- __func__, num_sections);
+ log_err("Invalid number of sections: %d\n", num_sections);
ret = EFI_LOAD_ERROR;
goto err;
}
efi_reloc = efi_alloc(virt_size,
loaded_image_info->image_code_type);
if (!efi_reloc) {
- printf("%s: Could not allocate %lu bytes\n",
- __func__, virt_size);
+ log_err("Out of memory\n");
ret = EFI_OUT_OF_RESOURCES;
goto err;
}
efi_reloc = efi_alloc(virt_size,
loaded_image_info->image_code_type);
if (!efi_reloc) {
- printf("%s: Could not allocate %lu bytes\n",
- __func__, virt_size);
+ log_err("Out of memory\n");
ret = EFI_OUT_OF_RESOURCES;
goto err;
}
rel = efi_reloc + opt->DataDirectory[rel_idx].VirtualAddress;
virt_size = ALIGN(virt_size, opt->SectionAlignment);
} else {
- printf("%s: Invalid optional header magic %x\n", __func__,
- nt->OptionalHeader.Magic);
+ log_err("Invalid optional header magic %x\n",
+ nt->OptionalHeader.Magic);
ret = EFI_LOAD_ERROR;
goto err;
}