summaryrefslogtreecommitdiff
path: root/lib/efi_loader
AgeCommit message (Collapse)AuthorFilesLines
2020-12-23sandbox: implement runtime system resetHeinrich Schuchardt1-1/+2
Implement a reset function that we can call after ExitBootServices(), when all driver model devices are gone. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2020-12-19dm: Avoid accessing seq directlySimon Glass1-2/+2
At present various drivers etc. access the device's 'seq' member directly. This makes it harder to change the meaning of that member. Change access to go through a function instead. The drivers/i2c/lpc32xx_i2c.c file is left unchanged for now. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-14dm: treewide: Rename 'platdata' variables to just 'plat'Simon Glass2-8/+8
We use 'priv' for private data but often use 'platdata' for platform data. We can't really use 'pdata' since that is ambiguous (it could mean private or platform data). Rename some of the latter variables to end with 'plat' for consistency. Signed-off-by: Simon Glass <sjg@chromium.org>
2020-12-10efi_loader: link partition to block deviceHeinrich Schuchardt1-0/+20
We provide a UEFI driver for block devices. When ConnectController() is called for a handle with the EFI_BLOCK_IO_PROTOCOL this driver creates the partitions. When DisconnectController() is called the handles for the partitions have to be deleted. This requires that the child controllers (partitions) open the EFI_BLOCK_IO_PROTOCOL of the controller (block IO device) with attribute EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-12-10efi_loader: make efi_protocol_open() non-staticHeinrich Schuchardt1-1/+1
Provide efi_protocol_open() as library function. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-12-10efi_loader: support EFI_LOAD_FILE_PROTOCOLHeinrich Schuchardt1-1/+48
Support loading images via the EFI_LOAD_FILE_PROTOCOL and EFI_LOAD_FILE2_PROTOCOL. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-12-10efi_loader: carve out efi_load_image_from_file()Heinrich Schuchardt1-9/+36
efi_load_image_from_file() should read via either of: * EFI_SIMPLE_FILE_SYSTEM_PROTOCOL * EFI_LOAD_FILE_PROTOCOL * EFI_LOAD_FILE2_PROTOCOL To make the code readable carve out a function to load the image via the file system protocol. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-12-10efi_loader: pass boot_policy to efi_load_image_from_pathHeinrich Schuchardt1-7/+9
Implementing support for loading images via the EFI_LOAD_FILE_PROTOCOL requires the boot policy as input for efi_load_image_from_path(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-12-10efi_loader: move EFI_LOAD_FILE2_PROTOCOL_GUIDHeinrich Schuchardt2-3/+3
The EFI_LOAD_FILE_PROTOCOL_GUID and EFI_LOAD_FILE2_PROTOCOL_GUID are needed to complement the implementation of the LoadFile() boot service. Remove a duplicate declaration of a variable for the EFI_LOAD_FILE2_PROTOCOL_GUID. Move the remaining declaration to efi_boottime.c. Add a variable for the EFI_LOAD_FILE_PROTOCOL_GUID. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-12-10efi_loader: resequence functions in efi_boottime.cHeinrich Schuchardt1-82/+82
For implementing support for the EFI_LOAD_FILE_PROTOCOL in the LoadImage() service we will have to call the LocateDevicePath() service. To avoid a forward declaration resequence the functions. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-12-10efi_loader: remove EFI_HII_CONFIG_ROUTING_PROTOCOLHeinrich Schuchardt3-7/+8
Our implementation of the EFI_HII_CONFIG_ROUTING_PROTOCOL is a mere stub, where all services return an error code. The protocol is neither needed for the EFI shell nor for the UEFI SCT. To reduce the code size remove it from the U-Boot binary. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-12-10efi_loader: don't set EFI_RT_SUPPORTED_UPDATE_CAPSULEHeinrich Schuchardt1-4/+0
The EFI_RT_PROPERTIES_TABLE configuration table indicates which runtime services are available at runtime. Even if CONFIG_EFI_RUNTIME_UPDATE_CAPSULE=y, we neither support UpdateCapsule() nor QueryCapsuleCapabilities() at runtime. Thus we should not set the corresponding flags EFI_RT_SUPPORTED_UPDATE_CAPSULE and EFI_RT_SUPPORTED_QUERY_CAPSULE_CAPABILITIES in RuntimeServicesSupported. Fixes: 2bc27ca8a04a ("efi_loader: define UpdateCapsule api") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-12-03efi_loader: add firmware management protocol for raw imageAKASHI Takahiro4-58/+194
In this commit, a very simple firmware management protocol driver is implemented. It will take a binary image in a capsule file and apply the data using dfu backend storage drivers via dfu_write_by_alt() interface. So "dfu_alt_info" variable should be properly set to specify a device and location to be updated. Please read README.dfu. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2020-12-03efi_loader: add firmware management protocol for FIT imageAKASHI Takahiro4-1/+314
In this commit, a very simple firmware management protocol driver is implemented. It will take a common FIT image firmware in a capsule file and apply the data using dfu backend storage drivers via update_fit() interface. So "dfu_alt_info" variable should be properly set to specify a device and location to be updated. Please read README.dfu. Fit image is a common file format for firmware update on U-Boot, and this protocol works neatly just as a wrapper for one. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2020-12-03efi_loader: capsule: support firmware updateAKASHI Takahiro3-12/+252
A capsule tagged with the guid, EFI_FIRMWARE_MANAGEMENT_CAPSULE_ID_GUID, is handled as a firmware update object. What efi_update_capsule() basically does is to load any firmware management protocol (or fmp) drivers contained in a capsule, find out an appropriate fmp driver and then invoke its set_image() interface against each binary in a capsule. In this commit, however, loading drivers is not supported. The result of applying a capsule is set to be stored in "CapsuleXXXX" variable, but its implementation is deferred to a fmp driver. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2020-12-03efi_loader: capsule: add capsule_on_disk supportAKASHI Takahiro3-0/+528
Capsule data can be loaded into the system either via UpdateCapsule runtime service or files on a file system (of boot device). The latter case is called "capsules on disk", and actual updates will take place at the next boot time. In this commit, we will support capsule on disk mechanism. Please note that U-Boot itself has no notion of "boot device" and all the capsule files to be executed will be detected only if they are located in a specific directory, \EFI\UpdateCapsule, on a device that is identified as a boot device by "BootXXXX" variables. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2020-12-03efi_loader: define UpdateCapsule apiAKASHI Takahiro5-54/+291
In this commit, skeleton functions for capsule-related API's are added under CONFIG_EFI_UPDATE_CAPSULE configuration. Detailed implementation for a specific capsule type will be added in the succeeding patches. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2020-12-03efi_loader: Introduce eventlog support for TCG2_PROTOCOLIlias Apalodimas3-23/+551
In the previous patches we only introduced a minimal subset of the EFI_TCG2_PROTOCOL protocol implementing GetCapability(). So let's continue adding features to it, introducing the GetEventLog() and HashLogExtendEvent() functions. In order to do that we first need to construct the eventlog in memory, specifically in EFI_BOOT_SERVICES_DATA memory and a configuration table from EFI_ACPI_MEMORY_NVS. U-Boot won't currently add any events to the log or measure any components, but will expose the necessary EFI APIs for applications to do so. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2020-11-29efi_loader: enable EFI_SET_TIME on sandbox and QEMU ARMHeinrich Schuchardt1-0/+1
Enable EFI_SET_TIME on the sandbox and QEMU ARM to ensure that we compile and test the relevant code. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-11-21efi_loader: parameter check in GetNextVariableName()Heinrich Schuchardt1-3/+8
If GetNextVariableName() is called with a non-existing combination of VariableName and VendorGuid, return EFI_INVALID_PARAMETER. If GetNextVariableName() is called with a string that is not zero terminated, return EFI_INVALID_PARAMETER. Reformat a line over 80 characters. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-11-21efi_loader: tcg2 protocol updatesIlias Apalodimas1-68/+92
On pull reuqest https://lists.denx.de/pipermail/u-boot/2020-November/432735.html V4 of the patchset was sent instead of the v5. This is the v4->v5 missing diff Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2020-11-14efi_loader: Add basic EFI_TCG2_PROTOCOL supportIlias Apalodimas4-0/+549
Since U-boot EFI implementation is getting richer it makes sense to add support for EFI_TCG2_PROTOCOL taking advantage of any hardware TPM available on the device. This is the initial implementation of the protocol which only adds support for GetCapability(). It's limited in the newer and safer TPMv2 devices. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Acked-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-11-14efi_loader: incorrect buffer size in efi_file_setinfo()Heinrich Schuchardt1-1/+1
When copying a string with must allocate a byte for the terminating '\0' in the target buffer. Fixes: fbe4c7df0087 ("efi_loader: enable file SetInfo()") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-11-14efi_loader: Add missing newline to log_{err,warning}Paulo Alcantara1-2/+2
Add missing newline to log messages in efi_rng_register() otherwise something like below would be shown Scanning disk virtio-blk#31... Found 2 disks Missing RNG device for EFI_RNG_PROTOCOLNo EFI system partition Signed-off-by: Paulo Alcantara (SUSE) <pc@cjr.nz> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-11-14efi_selftest: keep devices in ExitBootServices()Heinrich Schuchardt1-4/+9
When calling ExitBootServices during out unit tests we should not detach devices as we need console output for runtime tests. Fixes: 529441ca89b1 ("efi_loader: Disable devices before handing over control") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-11-09efi_loader: non-volatile variable not deleted from fileHeinrich Schuchardt1-0/+1
When deleting a non-volatile variable it was deleted from memory but the deletion was not persisted to the file system. SetVariable() may be called with attributes == 0 to delete a variable. To determine if the deletion shall be persisted we have to consider the non-volatile flag in the attributes of the deleted variable and not the value passed in the call parameter. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-10-30efi_loader: add efi_create_indexed_name()AKASHI Takahiro2-0/+37
This function will be used from several places in UEFI subsystem to generate some specific form of utf-16 variable name. For example, L"Capsule0001" Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Move function to separate module. Use char * as argument instead of u16 *. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-10-30efi_loader: add option to initialise EFI subsystem earlyAKASHI Takahiro1-0/+4
If this option, CONFIG_EFI_SETUP_EARLY, is enabled, the initialisation of UEFI subsystem will be done as part of U-Boot initialisation. Please note that this option won't be enabled explicitly by users, instead, should be enabled implicitly by other configuration options. Specifically, this feature will be utilised in implementing capsule-on-disk feature. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-10-30efi_loader: fix DisconnectController() for sole childHeinrich Schuchardt1-8/+11
If ChildHandle indicates the sole child of the driver, disconnect the driver. This fixes the test results for UEFI SCT 2.6 A sub-tests 5.1.3.12.43, 5.1.3.12.44, 5.1.3.12.45. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-10-27efi_loader: daylight saving timeHeinrich Schuchardt1-3/+16
Adjust the SetTime() and GetTime() runtime services to correctly convert the daylight saving time information when communicating with the RTC. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-10-27efi_loader: Disable devices before handing over controlIlias Apalodimas1-0/+6
U-Boot Driver Model is supposed to remove devices with either DM_REMOVE_ACTIVE_DMA or DM_REMOVE_OS_PREPARE flags set, before exiting. Our bootm command does that by explicitly calling calling "dm_remove_devices_flags(DM_REMOVE_ACTIVE_ALL);" and we also disable any USB devices. The EFI equivalent is doing none of those at the moment. As a result probing an fTPM driver now renders it unusable in Linux. During our (*probe) callback we open a session with OP-TEE, which is supposed to close with our (*remove) callback. Since the (*remove) is never called, once we boot into Linux and try to probe the device again we are getting a busy error response. Moreover all uclass (*preremove) functions won't run. So let's fix this by mimicking what bootm does and disconnect devices when efi_exit_boot_services() is called. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-10-27efi_loader: Sort header file orderingIlias Apalodimas1-4/+3
Order header files according to https://www.denx.de/wiki/U-Boot/CodingStyle Suggested-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-10-22common: rename getc() to getchar()Heinrich Schuchardt1-10/+10
The sandbox is built with the SDL2 library with invokes the X11 library which in turn calls getc(). But getc() in glibc is defined as int getc(FILE *) This does not match our definition. int getc(void) The sandbox crashes when called with parameter -l. Rename our library symbol getc() to getchar(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Tom Rini <trini@konsulko.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2020-10-19efi_loader: fix use after free in receive pathPatrick Wildt1-23/+69
With DM enabled the ethernet code will receive a packet, call the push method that's set by the EFI network implementation and then free the packet. Unfortunately the push methods only sets a flag that the packet needs to be handled, but the code that provides the packet to an EFI application runs after the packet has already been freed. To rectify this issue, adjust the push method to accept the packet and store it in a temporary buffer. The EFI application then gets the data copied from that buffer. This way the packet is cached until is is needed. The DM Ethernet stack tries to receive 32 packets at once, thus we better allocate as many buffers as the stack. Signed-off-by: Patrick Wildt <patrick@blueri.se> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-10-06efi_loader: QEMU CONFIG_EFI_GRUB_ARM32_WORKAROUND=nHeinrich Schuchardt1-0/+1
CONFIG_EFI_GRUB_ARM32 is only needed for architectures with caches that are not managed via CP15 (or for some outdated buggy versions of GRUB). It makes more sense to disable the setting per architecture than per defconfig. Move QEMU's CONFIG_EFI_GRUB_ARM32_WORKAROUND=n from defconfig to Kconfig. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-10-06efi_loader: illegal free in EFI_LOAD_FILE2_PROTOCOLHeinrich Schuchardt1-8/+9
strsep() changes the address that its first argument points to. We cannot use the changed address as argument of free(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2020-10-06efi_loader: description EFI_LOAD_FILE2_PROTOCOLHeinrich Schuchardt1-19/+23
U-Boot offers a EFI_LOAD_FILE2_PROTOCOL which the Linux EFI stub can use to load an initial RAM disk. Update the function comments of the implementation. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2020-09-27efi_loader: installation of EFI_RNG_PROTOCOLHeinrich Schuchardt3-5/+34
Having an EFI_RNG_PROTOCOL without a backing RNG device leads to failure to boot Linux 5.8. Only install the EFI_RNG_PROTOCOL if we have a RNG device. Reported-by: Scott K Logan <logans@cottsay.net> Cc: Neil Armstrong <narmstrong@baylibre.com> Cc: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-09-18efi_memory: refine overlap_only_ram descriptionMaxim Uvarov1-1/+1
Refine text for overlap_only_ram description to match to what exactly flag does and aling description with other functions. Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-09-15efi_loader: save global data pointer on RISC-VHeinrich Schuchardt1-9/+9
On RISC-V the global data pointer is stored in register gp. When a UEFI binary calls the EFI API we have to restore it. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-09-15efi_loader: efi_var_mem_notify_exit_boot_servicesHeinrich Schuchardt1-1/+1
efi_var_mem_notify_exit_boot_services() is invoked when ExitBootServices() is called by the UEFI payload. efi_var_mem_notify_exit_boot_services() should not be defined as __efi_runtime as it is invoking EFI_ENTRY() and EFI_EXIT() which themselves are not __efi_runtime. Fixes: f1f990a8c958 ("efi_loader: memory buffer for variables") Fixes: e01aed47d6a0 ("efi_loader: Enable run-time variable support for tee based variables") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
2020-09-06efi_loader: remove duplicate image size checkHeinrich Schuchardt1-4/+0
The image size is checked in efi_load_pe(). Avoid checking it twice. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-09-06efi_loader: error message if image not authenticatedHeinrich Schuchardt1-2/+4
Currently if the bootefi command fails due to missing authentication, the user gets no feedback. Write a log message 'Image not authenticated' if LoadImage() fails due to missing authentication. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-09-06efi_loader: log function in image loaderHeinrich Schuchardt1-22/+22
Use log_err() for error messages. Replace debug() by EFI_PRINT(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-08-24efi_loader: validate device path length in boot managerHeinrich Schuchardt1-4/+2
Bootxxxx variables are provided by the user and therefore cannot be trusted. We have to validate them before usage. A device path provided by a Bootxxxx variable must have an end node within the indicated device path length. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-08-24efi_loader: efi_dp_check_length()Heinrich Schuchardt1-0/+33
We need to check that device paths provided via UEFI variables are not malformed. Provide function efi_dp_check_length() to check if a device path has an end node within a given number of bytes. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-08-24efi_loader: ResetSystem() should not hangHeinrich Schuchardt1-3/+4
If ResetSystem() is not implemented at runtime, it should return instead of hanging in an endless loop. This allows the operating system to reset the system by other means as Linux does. It also matches what EDK II suggests in comments for functions ResetShutdown() and ResetWarm() in OvmfPkg/Library/ResetSystemLib/ResetSystemLib.c. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-08-14efi_loader: signature: correct a behavior against multiple signaturesAKASHI Takahiro2-85/+24
Under the current implementation, all the signatures, if any, in a signed image must be verified before loading it. Meanwhile, UEFI specification v2.8b section 32.5.3.3 says, Multiple signatures are allowed to exist in the binary’s certificate table (as per PE/COFF Section “Attribute Certificate Table”). Only one hash or signature is required to be present in db in order to pass validation, so long as neither the SHA-256 hash of the binary nor any present signature is reflected in dbx. This patch makes the semantics of signature verification compliant with the specification mentioned above. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2020-08-13efi_loader: variable: fix secure state initializationAKASHI Takahiro1-5/+5
Under the new file-based variable implementation, the secure state is always and falsely set to 0 (hence, the secure boot gets disabled) after the reboot even if PK (and other signature database) has already been enrolled in the previous boot. This is because the secure state is set up *before* loading non-volatile variables' values from saved data. This patch fixes the order of variable initialization and secure state initialization. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Fixes: 5f7dcf079de8 ("efi_loader: UEFI variable persistence")
2020-08-13efi_loader: signature: rework for intermediate certificates supportAKASHI Takahiro4-209/+184
In this commit, efi_signature_verify(with_sigdb) will be re-implemented using pcks7_verify_one() in order to support certificates chain, where the signer's certificate will be signed by an intermediate CA (certificate authority) and the latter's certificate will also be signed by another CA and so on. What we need to do here is to search for certificates in a signature, build up a chain of certificates and verify one by one. pkcs7_verify_one() handles most of these steps except the last one. pkcs7_verify_one() returns, if succeeded, the last certificate to verify, which can be either a self-signed one or one that should be signed by one of certificates in "db". Re-worked efi_signature_verify() will take care of this step. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>