summaryrefslogtreecommitdiffstats
path: root/lib/efi_loader
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch 'next'Tom Rini2021-04-0513-130/+1019
|\
| * efi_loader: Clean up file size calculationsIlias Apalodimas2021-03-251-15/+1
| | | | | | | | | | | | | | | | | | We recently added a common function for calculating file size, instead of copy pasting the code around. Switch one of the occurences over to the common function Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviwed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
| * efi_loader: Add an S-CRTM even for firmware versionIlias Apalodimas2021-03-251-0/+35
| | | | | | | | | | | | | | | | | | | | | | | | TCG PC Client Platform Firmware Profile Spec mandates that an S-CRTM event for the version identifier using the event type EV_S_CRTM_VERSION must be measured. So since we are trying to add more conformance into U-Boot, let's add the event using U_BOOT_VERSION_STRING, extend PCR[0] accordingly and log it in the EventLog Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
| * efi_loader: EFI TCG2 free efi memory on protocol failureIlias Apalodimas2021-03-251-8/+32
| | | | | | | | | | | | | | | | Current code doesn't free the efi allocated memory in case the protocol failed to install Fixes: c8d0fd582576 ("efi_loader: Introduce eventlog support for TCG2_PROTOCOL") Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
| * efi: Add ESRT to the EFI system tableJose Marinho2021-03-256-4/+535
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The ESRT is initialised during efi_init_objlist after efi_initialize_system_table(). The ESRT is recreated from scratch at the following events: - successful UpdateCapsule; - FMP instance install. The code ensures that every ESRT entry has a unique fw_class value. Limitations: - The ESRT is not updated if an FMP instance is uninstalled; - the fields image_type and flags are in the current implementation left undefined. Setting these values will require a per-platform function that returns the image_type/flags as a function of the image fw_class. CC: Heinrich Schuchardt <xypron.glpk@gmx.de> CC: Sughosh Ganu <sughosh.ganu@linaro.org> CC: AKASHI Takahiro <takahiro.akashi@linaro.org> CC: Ilias Apalodimas <ilias.apalodimas@linaro.org> CC: Andre Przywara <andre.przywara@arm.com> CC: Alexander Graf <agraf@csgraf.de> CC: nd@arm.com Signed-off-by: Jose Marinho <jose.marinho@arm.com> Remove two EFI_CALL() indirections. Move ESRT GUID in efidebug's list of GUIDs. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
| * efi_loader: Replace config option for initrd loadingIlias Apalodimas2021-03-253-98/+140
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Up to now we install EFI_LOAD_FILE2_PROTOCOL to load an initrd unconditionally. Although we correctly return various EFI exit codes depending on the file status (i.e EFI_NO_MEDIA, EFI_NOT_FOUND etc), the kernel loader, only falls back to the cmdline interpreted initrd if the protocol is not installed. This creates a problem for EFI installers, since they won't be able to load their own initrd and continue the installation. It also makes the feature hard to use, since we can either have a single initrd or we have to recompile u-boot if the filename changes. So let's introduce a different logic that will decouple the initrd path from the config option we currently have. When defining a UEFI BootXXXX we can use the filepathlist and store a file path pointing to our initrd. Specifically the EFI spec describes: "The first element of the array is a device path that describes the device and location of the Image for this load option. Other device paths may optionally exist in the FilePathList, but their usage is OSV specific" When the EFI application is launched through the bootmgr, we'll try to interpret the extra device path. If that points to a file that exists on our disk, we'll now install the load_file2 and the efi-stub will be able to use it. This opens up another path using U-Boot and defines a new boot flow. A user will be able to control the kernel/initrd pairs without explicit cmdline args or GRUB. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
| * efi_loader: Add helper functions for EFIIlias Apalodimas2021-03-254-0/+171
| | | | | | | | | | | | | | | | | | | | A following patch introduces a different logic for loading initrd's based on the EFI_LOAD_FILE2_PROTOCOL. Since similar logic can be applied in the future for other system files (i.e DTBs), let's add some helper functions which will retrieve and parse file paths stored in EFI variables. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
| * efi_loader: Add device path related functions for initrd via Boot####Ilias Apalodimas2021-03-251-5/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | On the following patches we allow for an initrd path to be stored in Boot#### variables. Specifically we encode in the FIlePathList[] of the EFI_LOAD_OPTIONS for each Boot#### variable. The FilePathList[] array looks like this: kernel - 0xff - VenMedia(initrd GUID) - initrd1 - 0x01 initrd2 - 0xff So let's add the relevant functions to concatenate and retrieve a device path based on a Vendor GUID. Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reformat function descriptions. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
| * efi_loader: Uart device pathHeinrich Schuchardt2021-03-252-9/+45
| | | | | | | | | | | | | | | | | | | | When uploading an EFI binary via the UART we need to assign a device path. * Provide devicepath node to text conversion for Uart() node. * Provide function to create Uart() device path. * Add UART support to efi_dp_from_name(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
| * efi_loader: NULL dereference in EFI consoleHeinrich Schuchardt2021-03-251-13/+38
| | | | | | | | | | | | | | | | | | | | Even if CONFIG_DM_VIDEO=y and stdout="vidconsole", a video device may not be available. Check the return values of the relevant functions. If no video output device is available, assume that the serial console is in use. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
| * efi: Fix compiler warningsSimon Glass2021-03-252-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This occur when building on Raspberry Pi 400 (32-bit ARM). Fix them. Examples: cmd/efidebug.c: In function ‘do_efi_capsule_update’: cmd/efidebug.c:75:49: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] ret = EFI_CALL(RT->update_capsule(&capsule, 1, (u64)NULL)); ^ include/efi_loader.h:104:9: note: in definition of macro ‘EFI_CALL’ typeof(exp) _r = exp; \ ^~~ cmd/efidebug.c:75:49: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] ret = EFI_CALL(RT->update_capsule(&capsule, 1, (u64)NULL)); ^ include/efi_loader.h:104:19: note: in definition of macro ‘EFI_CALL’ typeof(exp) _r = exp; \ ^~~ In file included from include/common.h:20, from lib/efi_loader/efi_capsule.c:9: lib/efi_loader/efi_capsule.c: In function ‘efi_update_capsule’: include/efi_loader.h:83:8: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 10 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=] debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \ ^~~~~~~~~~~~~~~~~~ include/linux/printk.h:37:21: note: in definition of macro ‘pr_fmt’ #define pr_fmt(fmt) fmt ^~~ include/log.h:229:2: note: in expansion of macro ‘log’ log(LOG_CATEGORY, LOGL_DEBUG, fmt, ##args); \ ^~~ include/log.h:249:2: note: in expansion of macro ‘debug_cond’ debug_cond(_DEBUG, fmt, ##args) ^~~~~~~~~~ include/efi_loader.h:83:2: note: in expansion of macro ‘debug’ debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \ ^~~~~ lib/efi_loader/efi_capsule.c:444:2: note: in expansion of macro ‘EFI_ENTRY’ EFI_ENTRY("%p, %lu, %llu\n", capsule_header_array, capsule_count, ^~~~~~~~~ lib/efi_loader/efi_capsule.c:444:19: note: format string is defined here EFI_ENTRY("%p, %lu, %llu\n", capsule_header_array, capsule_count, ~~^ %u Signed-off-by: Simon Glass <sjg@chromium.org> Replace (uintptr_t)NULL by 0. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
| * efi_loader: fix memory type for memory reservation blockMark Kettenis2021-03-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The (yet unreleased version of the) devicetree specification clearly states that: As with the /reserved-memory node, when booting via UEFI entries in the Memory Reservation Block must also be listed in the system memory map obtained via the GetMemoryMap() toi protect against allocations by UEFI applications. The memory reservation block entries should be listed with type EfiReservedMemoryType. This restores the behaviour that was changed by commit 4cbb2930bd8c ("efi_loader: consider no-map property of reserved memory"). Fixes: 4cbb2930bd8c ("efi_loader: consider no-map property of reserved memory") Signed-off-by: Mark Kettenis <kettenis@openbsd.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
| * efi_loader: disable GRUB_ARM32_WORKAROUND on ARCH_SUNXIHeinrich Schuchardt2021-03-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | GRUB_ARM32_WORKAROUND can be disabled on ARCH_SUNXI as the Allwinner SoCs only have a level 2 cache controlled via CP15 and not an architecturally defined cache. Having the cache available speeds up booting Linux. On ARCH_BCM283X it is already disabled via rpi_2_defconfig. But let's move this setting to Kconfig. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | efi_loader: typo 'devide path'Heinrich Schuchardt2021-03-311-1/+1
| | | | | | | | | | | | Fix a typo in helloworld.efi. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | efi_loader: Uart device path missing breakHeinrich Schuchardt2021-03-311-0/+2
| | | | | | | | | | | | | | | | | | In the devicepath node to text conversion for Uart nodes a break statement is missing. Indicated by Coverity Scan CID 330038 Fixes: 62df6e9c9994 ("efi_loader: Uart device path") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | efi_loader: Uart device pathHeinrich Schuchardt2021-03-192-9/+45
| | | | | | | | | | | | | | | | | | | | When uploading an EFI binary via the UART we need to assign a device path. * Provide devicepath node to text conversion for Uart() node. * Provide function to create Uart() device path. * Add UART support to efi_dp_from_name(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | efi_loader: NULL dereference in EFI consoleHeinrich Schuchardt2021-03-191-13/+38
| | | | | | | | | | | | | | | | | | | | Even if CONFIG_DM_VIDEO=y and stdout="vidconsole", a video device may not be available. Check the return values of the relevant functions. If no video output device is available, assume that the serial console is in use. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | efi: Fix compiler warningsSimon Glass2021-03-162-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This occur when building on Raspberry Pi 400 (32-bit ARM). Fix them. Examples: cmd/efidebug.c: In function ‘do_efi_capsule_update’: cmd/efidebug.c:75:49: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] ret = EFI_CALL(RT->update_capsule(&capsule, 1, (u64)NULL)); ^ include/efi_loader.h:104:9: note: in definition of macro ‘EFI_CALL’ typeof(exp) _r = exp; \ ^~~ cmd/efidebug.c:75:49: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] ret = EFI_CALL(RT->update_capsule(&capsule, 1, (u64)NULL)); ^ include/efi_loader.h:104:19: note: in definition of macro ‘EFI_CALL’ typeof(exp) _r = exp; \ ^~~ In file included from include/common.h:20, from lib/efi_loader/efi_capsule.c:9: lib/efi_loader/efi_capsule.c: In function ‘efi_update_capsule’: include/efi_loader.h:83:8: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 10 has type ‘size_t’ {aka ‘unsigned int’} [-Wformat=] debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \ ^~~~~~~~~~~~~~~~~~ include/linux/printk.h:37:21: note: in definition of macro ‘pr_fmt’ #define pr_fmt(fmt) fmt ^~~ include/log.h:229:2: note: in expansion of macro ‘log’ log(LOG_CATEGORY, LOGL_DEBUG, fmt, ##args); \ ^~~ include/log.h:249:2: note: in expansion of macro ‘debug_cond’ debug_cond(_DEBUG, fmt, ##args) ^~~~~~~~~~ include/efi_loader.h:83:2: note: in expansion of macro ‘debug’ debug("%sEFI: Entry %s(" format ")\n", __efi_nesting_inc(), \ ^~~~~ lib/efi_loader/efi_capsule.c:444:2: note: in expansion of macro ‘EFI_ENTRY’ EFI_ENTRY("%p, %lu, %llu\n", capsule_header_array, capsule_count, ^~~~~~~~~ lib/efi_loader/efi_capsule.c:444:19: note: format string is defined here EFI_ENTRY("%p, %lu, %llu\n", capsule_header_array, capsule_count, ~~^ %u Signed-off-by: Simon Glass <sjg@chromium.org> Replace (uintptr_t)NULL by 0. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | efi_loader: fix memory type for memory reservation blockMark Kettenis2021-03-161-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The (yet unreleased version of the) devicetree specification clearly states that: As with the /reserved-memory node, when booting via UEFI entries in the Memory Reservation Block must also be listed in the system memory map obtained via the GetMemoryMap() toi protect against allocations by UEFI applications. The memory reservation block entries should be listed with type EfiReservedMemoryType. This restores the behaviour that was changed by commit 4cbb2930bd8c ("efi_loader: consider no-map property of reserved memory"). Fixes: 4cbb2930bd8c ("efi_loader: consider no-map property of reserved memory") Signed-off-by: Mark Kettenis <kettenis@openbsd.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | efi_loader: disable GRUB_ARM32_WORKAROUND on ARCH_SUNXIHeinrich Schuchardt2021-03-161-1/+1
|/ | | | | | | | | | | GRUB_ARM32_WORKAROUND can be disabled on ARCH_SUNXI as the Allwinner SoCs only have a level 2 cache controlled via CP15 and not an architecturally defined cache. Having the cache available speeds up booting Linux. On ARCH_BCM283X it is already disabled via rpi_2_defconfig. But let's move this setting to Kconfig. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: carve out utf_to_cp()Heinrich Schuchardt2021-03-071-16/+3
| | | | | | | | Carve out a function to translate a Unicode code point to an 8bit codepage. Provide a unit test for the new function. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: move codepage 437 tableHeinrich Schuchardt2021-03-071-1/+1
| | | | | | Move the Unicode to codepage 437 table to charset.c Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: console size of vidconsoleHeinrich Schuchardt2021-03-071-1/+1
| | | | | | | | | | If stdout is 'vidconsole', we correctly set the console size. If stdout is 'vidconsole,serial', the video console is ignored. We should always evaluate the size of vidconsole if it is the primary console. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: limit output length for VenHw, VenMediaHeinrich Schuchardt2021-02-261-2/+4
| | | | | | | | | | | | | | VenHw and VenMedia device path nodes may carry vendor defined data of arbitrary length. When converting a device path node to text ensure that we do not overrun our internal buffer. In our implementation of EFI_DEVICE_PATH_TO_TEXT_PROTOCOL.ConvertDevicePathToText() we could first determine the output length and then allocate buffers but that would nearly double the code size. Therefore keep the preallocated buffers and truncate excessive device paths instead. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: ACPI tables must be in EfiACPIReclaimMemoryHeinrich Schuchardt2021-02-261-2/+1
| | | | | | | | | | | The UEFI spec does not allow ACPI tables to be in runtime services memory. It recommends EfiACPIReclaimMemory. Remove a superfluous check that the allocated pages are 16 byte aligned. EFI pages are 4 KiB aligned. Fixes: 86df34d42b05 ("efi_loader: Install ACPI configuration tables") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: multi part device paths to textHeinrich Schuchardt2021-02-211-5/+12
| | | | | | | | | | | | Our current implementation of EFI_DEVICE_PATH_TO_TEXT_PROTOCOL.ConvertDevicePathToText() truncates multi part device paths after the first part. We should convert all parts. Render device path instance ends as commas. This is not explicitly described in the UEFI spec but mimics what EDK II does. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
* Allow last block to be readJesper Schmitz Mouridsen2021-02-211-2/+2
| | | | | | | | | | | The last block is of size media->block_size Signed-off-by: Jesper Schmitz Mouridsen <jesper@schmitz.computer> Simplify expression. Apply same change to efi_disk_write_blocks(). Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* Merge branch '2021-02-02-drop-asm_global_data-when-unused'Tom Rini2021-02-156-0/+6
|\ | | | | | | - Merge the patch to take <asm/global_data.h> out of <common.h>
| * common: Drop asm/global_data.h from common headerSimon Glass2021-02-026-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | Move this out of the common header and include it only where needed. In a number of cases this requires adding "struct udevice;" to avoid adding another large header or in other cases replacing / adding missing header files that had been pulled in, very indirectly. Finally, we have a few cases where we did not need to include <asm/global_data.h> at all, so remove that include. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Tom Rini <trini@konsulko.com>
* | efi_loader: fix get_last_capsule()Heinrich Schuchardt2021-02-141-5/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fix get_last_capsule() leads to writes beyond the stack allocated buffer. This was indicated when enabling the stack protector. utf16_utf8_strcpy() only stops copying when reaching '\0'. The current invocation always writes beyond the end of value[]. The output length of utf16_utf8_strcpy() may be longer than the number of UTF-16 tokens. E.g has "CapsuleКиев" has 11 UTF-16 tokens but 15 UTF-8 tokens. Hence, using utf16_utf8_strcpy() without checking the input may lead to further writes beyond value[]. The current invocation of strict_strtoul() reads beyond the end of value[]. A non-hexadecimal value after "Capsule" (e.g. "CapsuleZZZZ") must result in an error. We cat catch this by checking the return value of strict_strtoul(). A value that is too short after "Capsule" (e.g. "Capsule0") must result in an error. We must check the string length of value[]. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | efi_loader: '.' and '..' are directoriesHeinrich Schuchardt2021-02-141-3/+1
| | | | | | | | | | | | | | | | '.' and '..' are directories. So when looking for capsule files it is sufficient to check that the attribute EFI_FILE_DIRECTORY is not set. We don't have to check for these special names. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | efi_loader: don't load beyond VirtualSizeAsherah Connor2021-02-141-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | PE section table entries' SizeOfRawData must be a multiple of FileAlignment, and thus may be rounded up and larger than their VirtualSize. We should not load beyond the VirtualSize, which is "the total size of the section when loaded into memory" -- we may clobber real data at the target in some other section, since we load sections in reverse order and sections are usually laid out sequentially. Signed-off-by: Asherah Connor <ashe@kivikakk.ee> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | efi_loader: VenMedia device path nodeHeinrich Schuchardt2021-02-041-0/+15
| | | | | | | | | | | | | | | | | | The Load File2 protocol exposes a device path with a VenMedia() node. Hence our implementation of the device path to text protocol should support this node. Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | efi_loader: install UEFI System Partition GUIDHeinrich Schuchardt2021-02-041-8/+7
| | | | | | | | | | | | | | | | | | On the handle for the UEFI System Partition we must install the System Partition GUID (with a NULL interface). Let the efidebug command display the GUID. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* | efi_loader: only check size if EFI_DT_APPLY_FIXUPSHeinrich Schuchardt2021-02-041-12/+13
|/ | | | | | | | | | | In the implementation of the EFI_DT_FIXUP_PROTOCOL: * Only check the buffer size when EFI_DT_APPLY_FIXUPS is set. * In this case the field totalsize of the device-tree may not exceed the buffer size. * Install device-tree only if EFI_DT_INSTALL_TABLE is set. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: switch to non-secure mode laterHeinrich Schuchardt2021-01-291-4/+0
| | | | | | | | | | | | | Some ARMv7 boards using PSCI require to be in secure-mode when booted via 'bootz' or 'bootm'. During distro-boot 'bootefi bootmgr' is called to check if booting via UEFI is possible. With the change we change the switch from secure mode to non-secure mode is moved from the UEFI subsystem setup to just before calling StartImage(). Cc: Jernej Škrabec <jernej.skrabec@gmail.com> Reported by: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: correct block IO alignment checkHeinrich Schuchardt2021-01-291-4/+6
| | | | | | | | | | If the field Media->IoAlign of the EFI block IO protocol is zero, no alignment is required. Our code required 4 GiB alignment in this case. Don't check buffer alignment if Media->IoAlign == 0. Fixes: f59f0825e8b9 ("efi_loader: parameter checks BLOCK_IO_PROTOCOL") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: correct EFI_BLOCK_IO_PROTOCOL.Media.LastBlockHeinrich Schuchardt2021-01-231-9/+21
| | | | | | | | | | | | | The field Media.LastBlock of the EFI_BLOCK_IO_PROTOCOL.Media was filled incorrectly both for block devices as well as for partitions. The field must be filled with the index of the last logical block (LBA): * block devices: device size minus 1 * partitions: partition size minus 1 Reported-by: Alexander von Gluck IV <kallisti5@unixzen.com> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: notification with TPL_APPLICATION not allowedHeinrich Schuchardt2021-01-231-1/+8
| | | | | | | | | | | | | | The UEFI specification requires event notification levels to be > TPL_APPLICATION and <= TPL_HIGH_LEVEL. With the patch the CreateEvent() and CreatedEventEx() services are changed to check that the notification level is not TPL_APPLICATION. Reference: UEFI Specification 2.8 Errata B, table 27 "TPL Restrictions", "Event Notification Levels" Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: capsule: fix SIZEOF_MISMATCH warningAKASHI Takahiro2021-01-231-1/+1
| | | | | | | | | | | | | | | | | CID 316361 says: > Passing argument "count * 8UL /* sizeof (*files) */" to > function "dlmalloc" and then casting the return value to "u16 **" is > suspicious. In this particular case "sizeof (u16 **)" happens to be equal > to "sizeof (u16 *)", but this is not a portable assumption. > > 767 tmp_files = malloc(count * sizeof(*files)); The change in this patch fixes the ambiguity. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Fixes: CID 316361 For readability use *tmp_files instead of tmp_files[0] Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: fix efi_load_image_from_path()Heinrich Schuchardt2021-01-231-4/+1
| | | | | | | Use the correct GUID when closing the file load protocol. Remove an unnecessary check (Coverity CID 316363). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: Avoid emitting efi_var_buf to .GOTIlias Apalodimas2021-01-202-2/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Atish reports that on RISC-V, accessing the EFI variables causes a kernel panic. An objdump of the file verifies that, since the global pointer for efi_var_buf ends up in .GOT section which is not mapped in virtual address space for Linux. <snip of efi_var_mem_find> 0000000000000084 <efi_var_mem_find>: 84: 715d addi sp,sp,-80 * objdump -dr 0000000000000086 <.LCFI2>: 86: e0a2 sd s0,64(sp) 88: fc26 sd s1,56(sp) 8a: e486 sd ra,72(sp) 8c: f84a sd s2,48(sp) 8e: f44e sd s3,40(sp) 90: f052 sd s4,32(sp) 92: ec56 sd s5,24(sp) 94: 00000497 auipc s1,0x0 94: R_RISCV_GOT_HI20 efi_var_buf 98: 0004b483 ld s1,0(s1) # 94 <.LCFI2+0xe> 98: R_RISCV_PCREL_LO12_I .L0 98: R_RISCV_RELAX *ABS* * objdump -t 0000000000000084 g F .text.efi_runtime 00000000000000b8 efi_var_mem_find With the patch applied: * objdump -dr 0000000000000086 <.LCFI2>: 86: e0a2 sd s0,64(sp) 88: fc26 sd s1,56(sp) 8a: e486 sd ra,72(sp) 8c: f84a sd s2,48(sp) 8e: f44e sd s3,40(sp) 90: f052 sd s4,32(sp) 92: ec56 sd s5,24(sp) 94: 00000497 auipc s1,0x0 94: R_RISCV_PCREL_HI20 .LANCHOR0 94: R_RISCV_RELAX *ABS* 98: 00048493 mv s1,s1 98: R_RISCV_PCREL_LO12_I .L0 98: R_RISCV_RELAX *ABS* * objdump -t 0000000000000008 l O .data.efi_runtime 0000000000000008 efi_var_buf On arm64 this works, because there's no .GOT entries for this and everything is converted to relative references. * objdump -dr (identical pre-post patch, only the new function shows up) 00000000000000b4 <efi_var_mem_find>: b4: aa0003ee mov x14, x0 b8: 9000000a adrp x10, 0 <efi_var_mem_compare> b8: R_AARCH64_ADR_PREL_PG_HI21 .data.efi_runtime bc: 91000140 add x0, x10, #0x0 bc: R_AARCH64_ADD_ABS_LO12_NC .data.efi_runtime c0: aa0103ed mov x13, x1 c4: 79400021 ldrh w1, [x1] c8: aa0203eb mov x11, x2 cc: f9400400 ldr x0, [x0, #8] d0: b940100c ldr w12, [x0, #16] d4: 8b0c000c add x12, x0, x12 So let's switch efi_var_buf to static and create a helper function for anyone that needs to update it. Fixes: e01aed47d6a0 ("efi_loader: Enable run-time variable support for tee based variables") Reported-by: Atish Patra <atishp@atishpatra.org> Tested-by: Atish Patra <atish.patra@wdc.com> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: remove EFI_UNICODE_COLLATION_PROTOCOLHeinrich Schuchardt2021-01-203-50/+6
| | | | | | | | | | | | In EFI 1.10 a version of the Unicode collation protocol using ISO 639-2 language codes existed. This protocol is not part of the UEFI specification any longer. It was however required to run the UEFI Self Certification Test (SCT) II, version 2.6, 2017. So we implemented it for the sole purpose of running the SCT. As the SCT does not need the protocol anymore it is time for removal. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: EFI_DEVICE_PATH_UTILITIES_PROTOCOL configurableHeinrich Schuchardt2021-01-203-1/+10
| | | | | | | | | | Allow the EFI_DEVICE_PATH_UTILITIES_PROTOCOL to be disabled via configuration. On systems that are very tight on U-Boot image size we may want to disable the protocol. As it is required to run the UEFI Shell enable it by default. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: make EFI_DT_FIXUP_PROTOCOL configurableHeinrich Schuchardt2021-01-203-5/+12
| | | | | | Allow EFI_DT_FIXUP_PROTOCOL to be disabled via configuration. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: fixup protocol, avoid forward declarationHeinrich Schuchardt2021-01-201-10/+17
| | | | | | | | Avoid a forward declaration. Add a missing function description. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: make the UEFI boot manager configurableHeinrich Schuchardt2021-01-202-1/+9
| | | | | | | | | Some boards are very tight on the binary size. Booting via UEFI is possible without using the boot manager. Provide a configuration option to make the boot manager available. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: move load options to new moduleHeinrich Schuchardt2021-01-193-135/+150
| | | | | | | Move all load options related functions to a new module. So that they can be compiled independently. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: implement EFI_DT_FIXUP_PROTOCOLHeinrich Schuchardt2021-01-133-0/+169
| | | | | | | | | | A boot manager like GRUB can use the protocol to * apply U-Boot's fix-ups to the a device-tree * let U-Boot make memory reservations according to the device-tree * install the device-tree as a configuration table Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: remove outdated TODO in efi_memory.cHeinrich Schuchardt2021-01-131-2/+0
| | | | | | | In efi_mem_sort() adjacent memory regions of same type are coalesced. Remove the remark "Merging of adjacent free regions is missing". Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>