summaryrefslogtreecommitdiff
path: root/lib/efi_loader
AgeCommit message (Collapse)Author
2019-04-23efi_loader: consistent naming of protocol GUIDsHeinrich Schuchardt
We should consistently use the same name for protocol GUIDs as defined in the UEFI specification. Not adhering to this rule has led to duplicate definitions for the EFI_LOADED_IMAGE_PROTOCOL_GUID. Adjust misnamed protocol GUIDs. Adjust the text for the graphics output protocol in the output of the `efidebug dh` command. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-23efi_loader: export root node handleAKASHI Takahiro
This is a preparatory patch. The root node handle will be used as a dummy parent handle when invoking an EFI image from bootefi/bootmgr command. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Rebased. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-23efi_loader: efi_setup_loaded_image() handle missing file nameAKASHI Takahiro
This is a preparatory patch. efi_dp_split_file_path() is used to create device_path and file_path from file_path for efi_setup_loaded_image(). In a special case, however, of HARDWARE_DEVICE/MEMORY, it doesn't work expectedly since this path doesn't contain any FILE_PATH sub-type. This patch makes a workaround. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Adjust the logic such that for all paths that do no end on a media file path we return NULL as file_path. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-12efi_loader: simplify protocol installationHeinrich Schuchardt
By using InstallMultipleProtocolInterfaces() the coding for installing protocol interfaces on the root node can be simplified. Suggested-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-12efi_loader: export efi_install_multiple_protocol_interfacesHeinrich Schuchardt
Export function efi_install_multiple_protocol_interfaces() so that we can call it in others parts of the UEFI subsystem. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-12efi_loader: update virtual address in efi_mem_carve_outHeinrich Schuchardt
Handle virtual address in efi_mem_carve_out() function when a new region is created to avoid issue in EFI memory map. Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com> At boottime physical and virtual addressed have to be the same. This allowed to simplify the proposed logic. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-12efi_loader: add protection for block_devPatrick Delaunay
Check the value of block_dev before to use this pointer. This patch solves problem for the command "load" when ubifs is previously mounted: in this case the function blk_get_device_part_str("ubi 0") don't return error but return block_dev = NULL and then data abort. Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-12efi_loader: fix setting PlatformLangHeinrich Schuchardt
The UEFI variables PlatformLang and PlatformLangCodes specify the current firmware language and the list of all available languages. Currently their values are hard coded. With the patch a new configuration variable EFI_PLATFORM_LANG_CODES is provided. When initializing the UEFI subsystem this configuration variable is used to initialize PlatformLangCodes. The value of variable PlatformLang is read. If it is not set, the first language specified in EFI_PLATFORM_LANG_CODES is used to initialize PlatformLang. Suggested-by: Takahiro Akashi <takahiro.akashi@linaro.org> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-12efi_loader: move efi_save_gd() call to board_r.cHeinrich Schuchardt
The first functions of the UEFI sub-system are invoked before reaching the U-Boot shell, e.g. efi_set_bootdev(), efi_dp_from_name(), efi_dp_from_file(). We should be able to print out device paths for debugging purposes here. When printing device paths via printf("%pD\n", dp) this invokes functions defined as EFIAPI. So efi_save_gd() must be called beforehand. So let's move the efi_save_gd() call to function initr_reloc_global_data(() in board_r.c. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-12efi_loader: remove stray #define LOG_CATEGORY LOGL_ERRHeinrich Schuchardt
The statement '#define LOG_CATEGORY LOGL_ERR' makes not sense. LOGL_ERR is not a LOG_CATEGORY. Remove the statement. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-12efi_loader: enable HII protocols by defaultHeinrich Schuchardt
As the UEFI shell requires the HII protocols let's enable them by default. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-12efi_loader: assign HII protocols to root nodeHeinrich Schuchardt
We should not install the HII protocols on every loaded image. It is sufficient to install them once on the root node. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: correct CTRL-A - CTRL-Z console inputHeinrich Schuchardt
In the extended text input protocol CTRL-A - CTRL-Z have to be signaled as Unicode characters a-z or A-Z depending on the shift state and not as 0x01 to 0x1a. Update Python unit test. This patch is required for using the EFI shell `edit` command. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: enable file SetInfo()Heinrich Schuchardt
EFI shell command edit uses the SetInfo() methods to unset the read only attribute of the file to be edited. So let efi_file_setinfo() return success in this case. Return an error if the function is called for to rename or resize a file as we do not support this yet. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: correct file creationHeinrich Schuchardt
The EFI shell expects that after opening a file with EFI_FILE_MODE_CREATE GetInfo() succeeds. Up to now we do not actually create the file when method Open() of the EFI_FILE_PROTOCOL is called. If method Open() of the EFI_FILE_PROTOCOL is called with EFI_FILE_MODE_CREATE and the file does not yet exist, call fs_write() with a buffer size of zero to actually create the file. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: debug output file handle in efi_file_open()Heinrich Schuchardt
For debugging it is helpful to know the address of the file handle created by the Open() method of the EFI file protocol. So let's write it with EFI_PRINT(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: boottime: export efi_[un]load_image()AKASHI Takahiro
Those two functions will be used later to re-implement do_bootefi_exec(). Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: boottime: add loaded image device path protocol to image handleAKASHI Takahiro
To meet UEFI spec v2.7a section 9.2, we should add EFI_LOADED_IMAGE_DEVICE_PATH_PROTOCOL to image handle, instead of EFI_DEVICE_PATH_PROTOCOL. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: variables PlatformLang and PlatformLangCodesHeinrich Schuchardt
Since TianoCore EDK2 commit d65f2cea36d1 ("ShellPkg/CommandLib: Locate proper UnicodeCollation instance") in edk2 the UEFI Shell crashes if EFI variable PlatformLang is not defined. As this variable is anyway prescribed in the UEFI 2.7 spec let's define it to L"en-US". Use the same value for PlatformLangCodes that defines the list of all supported languages. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: EFI_PRINT instead of debug for memory servicesHeinrich Schuchardt
For debug messages inside EFI API functions we should use the EFI_PRINT macro which gives us well aligned output like: EFI: Entry efi_allocate_pool_ext(4, 14, 000000007edd7718) EFI: efi_add_memory_map: 0x7dcfa000 0x1 4 yes EFI: Exit: efi_allocate_pool_ext: 0 Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: EFI_PRINT instead of debug for variable servicesHeinrich Schuchardt
For debug messages inside EFI API functions we should use the EFI_PRINT macro which gives us well aligned output like: EFI: Entry efi_get_variable("PlatformLang" ...) EFI: get 'efi_8be4df61-93ca-11d2-aa0d-00e098032b8c_PlatformLang' EFI: Exit: efi_get_variable: 14 Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: parameter checks in StartImage and Exit()Heinrich Schuchardt
Add parameter checks in the StartImage() and Exit() boottime services: - check that the image handle is valid and has the loaded image protocol installed - in StartImage() record the current image - in Exit() check that the image is the current image Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: rearrange boottime service functionsHeinrich Schuchardt
To avoid forward declarations move efi_start_image() and efi_exit() down. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: sanity checks when freeing memoryHeinrich Schuchardt
Use a checksum to validate that efi_free_pool() is only called for memory allocated by efi_allocated_pool(). Add a plausibility check to efi_free_pages() checking that the address passed is page aligned. Update related function comments to match Sphinx style. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: set image_base and image_size to correct valuesAKASHI Takahiro
Currently, image's image_base points to an address where the image was temporarily uploaded for further loading. Since efi_loader relocates the image to final destination, image_base and image_size should reflect that. This bug was detected in UEFI SCT, "Loaded Image Protocol Test - test 2," which shows that 'Unload' function doesn't fit into a range suggested by image_base and image_size. TestCase/UEFI/EFI/Protocol/LoadedImage/BlackBoxTest/ LoadedImageBBTestMain.c:1002 Changes in this patch also includes: * reverts a patch, "efi_loader: save image relocation address and size" since newly added fields are no longer needed. * copy PE headers as well since those information will be needed for module loading, in particular, at gurb. (This bug was reported by Heinrich.) Reported-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Rebase patch. Remove unused fields from struct efi_loaded_image_obj. Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: bootmgr: support BootNext and BootCurrent variable behaviorAKASHI Takahiro
See UEFI v2.7, section 3.1.2 for details of the specification. With efidebug command, you can run any EFI boot option as follows: => efi boot add 1 SHELL ... => efi boot add 2 HELLO ... => efi boot order 1 2 => efi bootmgr (starting SHELL ...) => efi boot next 2 => efi bootmgr (starting HELLO ...) => env print -e <snip ...> BootCurrent: {boot,run}(blob) 00000000: 02 00 .. BootOrder: {boot,run}(blob) 00000000: 01 00 02 00 .... Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-07efi_loader: release file buffer after loading imageHeinrich Schuchardt
Commit 0e18f584de59 ("efi_loader: LoadImage: always allocate new pages") ensured that whether we load an image from file or from memory we end up with the same number of newly allocated buffers. But essentially we ended up with one buffer too many in both cases: efi_load_pe() copies and rebases the UEFI image. We do not need the buffer with the file contents afterwards. Fixes: 0e18f584de59 ("efi_loader: LoadImage: always allocate new pages") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-03-27efi_loader: TODO for the EFI file protocolHeinrich Schuchardt
We currently only support EFI_FILE_PROTOCOL_REVISION while UEFI specs 2.4 - 2.7 prescribe EFI_FILE_PROTOCOL_REVISION2. Add a todo. Add missing constants for the EFI file protocol revision. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-03-20efi_loader: superfluous conversion in efi_file_open()Heinrich Schuchardt
printf("%ls", ..) expects u16 * as argument to print. There is not need for a conversion to wchar_t *. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-03-20efi_loader: remove superfluous check in efi_setup_loaded_image()Heinrich Schuchardt
It does not make any sense to check if a pointer is NULL if we have dereferenced it before. Reported-by: Coverity (CID 185827) Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-03-20efi_loader: missing return in efi_get_next_variable_name()Heinrich Schuchardt
Add a missing return statement in efi_get_next_variable_name(). Reported-by: Coverity (CID 185834) Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-03-20efi_loader: endless loop in add_strings_package()Heinrich Schuchardt
Avoid an endless loop in add_strings_package(). Suggested-by: Takahiro Akashi <takahiro.akashi@linaro.org> Reported-by: Coverity (CID 185833) Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-03-20efi_loader: correct parameter size in efi_allocate_poolHeinrich Schuchardt
efi_allocate_pages() expects a (uint64_t *) pointer to pass the address of the assigned memory. If we pass the address of a pointer here, an illegal memory access occurs on 32bit systems. Fixes: 282a06cbcae8 ("efi_loader: Expose U-Boot addresses in memory map for sandbox") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-03-10efi_loader: Fix serial console size detectionMatthias Brugger
Function term_read_reply tries to read from the serial console until the end_char was read. This can hang forever if we are, for some reason, not able to read the full response (e.g. serial buffer too small, frame error). This patch moves the timeout detection into term_read_reply() to assure we will make progress. Fixes: 6bb591f704 ("efi_loader: query serial console size reliably") Signed-off-by: Matthias Brugger <mbrugger@suse.com> Throw missing error when an incomplete reply for the cursor position is received. Change type of argument of term_get_char() *s32. This renders the function reusable in efi_cin_read_key(). Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-03-02efi_loader: HII protocols: debug messagesHeinrich Schuchardt
When package types are not supported by our implementation of the HII database protocol supported error messages are displayed. Essentially the output is only needed for debugging. By using EFI_PRINT() the messages are only written for in debug mode and with correct indentation. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-03-02efi_loader: HII protocols: fix new_package_list()Heinrich Schuchardt
In new_package_list() we call new_packagelist() to create a new package list. Next we try to add the packages which fails for form packages. Due to this error we call free_packagelist(). Now in free_packagelist() list_del() is called for an uninitialized field hii->link. This leads to changing random memory addresses. To solve the problem move the initialization of hii->link to new_packagelist(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
2019-03-02efi_loader: do not add \ in efi_fs_from_name()Heinrich Schuchardt
In the `efidebug boot add` command we do not want an unsolicited leading backslash added to the file name. There is no good reason to mark a loaded file with a backslash as absolute. Anyway when reading files the file name will be interpreted as relative to root directory of the device. So let's get rid of this backslash. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-25efi_loader: define load option attributesAKASHI Takahiro
See UEFI specification v2.7a, section 3.1.3, "Load Option Processing." Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-25efi_loader: fix entry count in bootmgrHeinrich Schuchardt
Since commit 914df75b0c97 ("efi_loader: fix EFI entry counting") entry_count is already set to 1 before efi_bootmgr_load() is called. So we should not increment it when entering the function. Without the patch an assert error occurs in efi_get_variable() if DEBUG is defined. Fixes: 914df75b0c97 ("efi_loader: fix EFI entry counting") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-25efi_loader: error message if BootOrder not definedHeinrich Schuchardt
For booting via `bootefi bootmgr` it is necessary that the EFI variable BootOrder is defined. Provide a diagnostic message if the variable is missing. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-16efi_loader: do not miss last relocation blockHeinrich Schuchardt
If the last block in the relocation table contains only a single relocation, the current coding ignores it. Fix the determination of the end of the relocation table. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-16efi_loader: documentation of image loaderHeinrich Schuchardt
- Add missing function descriptions. - Update existing function descriptions to match Sphinx style. - Add lib/efi_loader/efi_image_loader.c to the input files for Sphinx generated documentation. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-16efi_loader: fix EFI entry countingHeinrich Schuchardt
`bootefi selftest` fails on qemu-x86_defconfig if efi_selftest() is not invoked using EFI_CALL(). Likewise we call the entry point of EFI payloads with EFI_CALL(efi_start_image()). entry_count indicates if we are in U-Boot (1) or in EFI payload code (0). As we start in U-Boot code the initial value has to be 1. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-16efi_loader: use efi_start_image() for bootefiHeinrich Schuchardt
Remove the duplicate code in efi_do_enter() and use efi_start_image() to start the image invoked by the bootefi command. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-16efi_loader: set entry point in efi_load_pe()Heinrich Schuchardt
Up to now efi_load_pe() returns the entry point or NULL in case of an error. This does not allow to return correct error codes from LoadImage(). Let efi_load_pe() return a status code and fill in the entry point in the corresponding field of the image object. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-16efi_loader: LoadImage: always allocate new pagesHeinrich Schuchardt
If we want to properly unload images in Exit() the memory should always be allocated in the same way. As we allocate memory when reading from file we should do the same when the original image is in memory. A further patch will be needed to free the memory when Exit() is called. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-16efi_loader: error handling in efi_setup_loaded_image()Heinrich Schuchardt
In case of an error we should set the returned pointers to NULL. This ensures that an illegal free does not occur even if the caller calls free() for the handles. If protocols cannot be installed, release all resources. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-16efi_loader: comments for efi_file_from_path()Heinrich Schuchardt
Add more comments for efi_file_from_path(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-16efi_loader: efi_dp_split_file_path() error handlingHeinrich Schuchardt
If the path passed to efi_dp_split_file_path() does not contain a reference to a file it returns EFI_OUT_OF_RESOURCES. This does not properly indicate the kind of the problem that occurred. Return EFI_INVALID_PARAMETER instead. Update function description. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-13efi_loader: fix EFI_FILE_PROTOCOL.GetInfo()Heinrich Schuchardt
We check the existence of files with fs_exist(). This function calls fs_close(). If we do not set the active block device again fs_opendir() fails and we do not set the flag EFI_FILE_DIRECTORY. Due to this error the `cd` command in the EFI shell fails. So let's add the missing set_blk_dev(fh) call. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>