summaryrefslogtreecommitdiffstats
path: root/lib/efi_loader/efi_file.c
Commit message (Collapse)AuthorAgeFilesLines
* efi_loader: loosen buffer parameter check in efi_file_read_intPeng Fan2021-05-181-1/+1
| | | | | | | | | | | | | | | | | | | This is same issue as https://bugzilla.redhat.com/show_bug.cgi?id=1733817, but that fix was wrongly partial reverted. When reading a directory, EFI_BUFFER_TOO_SMALL should be returned when the supplied buffer is too small, so a use-case is to call EFI_FILE_PROTOCOL.Read() with *buffer_size=0 and buffer=NULL to obtain the needed size before doing the actual read. So remove the check only for directory reading, file reading already do the check by itself. Fixes: db12f518edb0("efi_loader: implement non-blocking file services") Signed-off-by: Peng Fan <peng.fan@nxp.com> Cc: Stefan Sørensen <stefan.sorensen@spectralink.com> Tested-by: Peter Robinson <pbrobinson@gmail.com> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: Add helper functions for EFIIlias Apalodimas2021-03-251-0/+39
| | | | | | | | | | 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: implement non-blocking file servicesHeinrich Schuchardt2021-01-131-51/+266
| | | | | | | Implement services OpenEx(), ReadEx(), WriteEx(), FlushEx() of the EFI_FILE_PROTOCOL. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: incorrect buffer size in efi_file_setinfo()Heinrich Schuchardt2020-11-141-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>
* efi_loader: loosen buffer parameter check in efi_file_readStefan Sørensen2020-07-221-1/+8
| | | | | | | | | | | | | | | When reading a directory, EFI_BUFFER_TOO_SMALL should be returned when the supplied buffer is too small, so a use-case is to call efi_file_read with *buffer_size=0 and buffer=NULL to obtain the needed size before doing the actual read. So move the buffer!=NULL check to after the buffer size has been checked. This fix allows the Redhat shim fallback to run and e.g. Fedora 32 now boots out of the box. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* common: Drop log.h from common headerSimon Glass2020-05-181-0/+1
| | | | | | Move this header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
* common: Drop part.h from common headerSimon Glass2020-05-181-0/+1
| | | | | | Move this uncommon header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
* part: Drop disk_partition_t typedefSimon Glass2020-05-181-1/+1
| | | | | | | We should not be using typedefs and these make it harder to use forward declarations (to reduce header file inclusions). Drop the typedef. Signed-off-by: Simon Glass <sjg@chromium.org>
* efi_loader: adjust file system infoHeinrich Schuchardt2020-01-071-2/+9
| | | | | | | | | | | | | | | | When the GetInfo() method of the EFI_FILE_PROTOCOL is called to retrieve the file system info we claim that the volume is read only and has no free space. This leads to failures in programs that check this information before writing to the volume like SCT's InstallSct.efi. Currently there is no function to determine these parameters in U-Boot. So let's return optimistic values: Return that the volume is writable. Return the volume size as free space. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: parameter checks EFI_FILE_PROTOCOL.SetInfo()Heinrich Schuchardt2019-09-111-6/+4
| | | | | | | | | | We do not support volume label changes. No parameter checks are needed here. When the info for as file is changed the buffer must always contain a file name. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: check parameters EFI_FILE_PROTOCOL.GetInfo()Heinrich Schuchardt2019-09-091-0/+6
| | | | | | | | | Check the parameters of EFI_FILE_PROTOCOL.GetInfo() to avoid possible NULL dereference. Check the buffer size for EFI_FILE_SYSTEM_INFO. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: volume name in EFI_FILE_PROTOCOL.GetInfo()Heinrich Schuchardt2019-09-091-6/+12
| | | | | | | | We cannot determine the volume name in U-Boot. Instead of providing a dummy volume name in case of EFI_FILE_SYSTEM_INFO and EFI_UNSUPPORTED in case of EFI_FILE_SYSTEM_VOLUME_LABEL consistently return an empty string. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: EFI_FILE_PROTOCOL rev 2 stubHeinrich Schuchardt2019-09-091-5/+31
| | | | | | | The UEFI specification requires to implement version 2 of the EFI_FILE_PROTOCOL. Provide the missing functions as stubs. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: file size checksHeinrich Schuchardt2019-09-091-29/+40
| | | | | | | | | | The file size has to be determined in multiple places. Factor out a common function. If on entry into EFI_FILE_PROTOCOL.Read() the current position is beyond the end of the file, return EFI_DEVICE_ERROR. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: correct reading of directoriesHeinrich Schuchardt2019-09-091-18/+5
| | | | | | | | | | | | | | | | | EFI_FILE_PROTOCOL.Read() is used both to read files and directories. When reaching the end of a directory we always have to return buffer size zero irrespective of the incoming buffer size. (The described scenario for a Shim quirk cannot arise because every directory has at least '.' and '..' as entries.) Even when the buffer_size is too small multiple times we have to keep a reference to our last read directory entry. When we return to the start of the directory via SetPosition() we must remove the reference to a previously kept directory entry. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: eliminate inline function ascii2unicode()Heinrich Schuchardt2019-09-091-8/+15
| | | | | | | ascii2unicode() can only convert characters 0x00-0x7f from UTF-8 to UTF-16. Use utf8_utf16_strcpy() instead. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: EFI_FILE_PROTOCOL.Write() check argsHeinrich Schuchardt2019-09-091-10/+41
| | | | | | | | | | | Check the parameters passed to Write(): * cannot write to directories (UEFI SCT 2017, 5.7.3.5.15) * cannot write to file opened read only (UEFI SCT 2017, 5.7.3.5.16) Add missing comments. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: unaligned access in efi_file_from_path()Heinrich Schuchardt2019-07-161-1/+6
| | | | | | | | The device path structure is packed. So no assumption on the alignment is possible. Copy the file name in efi_file_from_path() to assure there is no unaligned access. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: Delete() return EFI_WARN_DELETE_FAILUREHeinrich Schuchardt2019-06-201-8/+2
| | | | | | | If EFI_FILE_PROTOCOL.Delete() fails, always close the handle and return EFI_WARN_DELETE_FAILURE. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: enable file SetInfo()Heinrich Schuchardt2019-04-071-2/+65
| | | | | | | | | | | 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>
* efi_loader: correct file creationHeinrich Schuchardt2019-04-071-8/+27
| | | | | | | | | | | | 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>
* efi_loader: debug output file handle in efi_file_open()Heinrich Schuchardt2019-04-071-2/+4
| | | | | | | | 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>
* efi_loader: TODO for the EFI file protocolHeinrich Schuchardt2019-03-271-0/+4
| | | | | | | | | | 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>
* efi_loader: superfluous conversion in efi_file_open()Heinrich Schuchardt2019-03-201-1/+1
| | | | | | | 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>
* efi_loader: comments for efi_file_from_path()Heinrich Schuchardt2019-02-161-1/+11
| | | | | | Add more comments for efi_file_from_path(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
* efi_loader: fix EFI_FILE_PROTOCOL.GetInfo()Heinrich Schuchardt2019-02-131-0/+4
| | | | | | | | | | | | 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>
* efi_loader: use u16* for file nameHeinrich Schuchardt2019-02-131-7/+7
| | | | | | | | | UTF-16 strings in our code should all be u16 *. Fix an inconsistency for file names which may lead to a warning for printf("%ls", ). Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: Add a wchar_t cast in efi_file_open()Simon Glass2019-01-141-2/+2
| | | | | | | The printf() string here is not actually correct. Add a cast to avoid a warning when checking is enabled. Signed-off-by: Simon Glass <sjg@chromium.org>
* efi_loader: use u16* for UTF16 stringsHeinrich Schuchardt2018-12-021-1/+1
| | | | | | | We should be consistent in the types that we use to store Unicode strings. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: superfluous statement in is_dir()Heinrich Schuchardt2018-10-161-1/+8
| | | | | | | | | | | When is_dir() is called we have already execute set_blk_dev(fh). So don't call it again. This fixes CoverityScan CID 184093. Reported-by: Tom Rini <trini@konsulko.com> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: correct signature of GetPosition, SetPositionHeinrich Schuchardt2018-10-161-8/+31
| | | | | | | | | | | | | | | | | The UEFI spec requires that file positions are passed as u64 in GetPosition() and SetPosition(). Check if the file handle points to a directory in GetPosition(). Provide a unit test for GetPosition() and SetPosition(). Fix Coverity warning CID 184079 (CONSTANT_EXPRESSION_RESULT). Add comments. Fixes: b6dd57773719 ("efi_loader: use correct types in EFI_FILE_PROTOCOL") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: check parameter new_handle of efi_file_open()Heinrich Schuchardt2018-09-231-1/+1
| | | | | | | | We should not check parameter file twice. We should check parameter new_handle. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: more debug info for efi_file_getinfo()Heinrich Schuchardt2018-09-231-1/+1
| | | | | | | | efi_file_getinfo() is called with a GUID. In EFI_ENTRY use %pUl as format type. This way the GUID is printed in debug mode. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi: Correct the operation of efi_file_write()Simon Glass2018-09-231-4/+2
| | | | | | | | We should not directly cast between pointers and addresses since it breaks sandbox. Fix this and simplify the code in file_read(). Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: loosen check of parameters of efi_file_open()Heinrich Schuchardt2018-09-231-1/+10
| | | | | | | | | | | | The UEFI spec requires that attributes are only set for when EFI_FILE_MODE_CREATE is set in open_mode. The SCT tries to read a directory with EFI_FILE_DIRECTORY. As EDK2 allows this we should not be more strict. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: provide description of file_open()Heinrich Schuchardt2018-09-231-2/+12
| | | | | | | Replace urban slang by proper description. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: check parameters of efi_file_open()Heinrich Schuchardt2018-09-231-4/+26
| | | | | | | Check the parameters of efi_file_open(). Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: implement a file deleteAKASHI Takahiro2018-09-231-1/+13
| | | | | | | | 'Delete' will be implemented here by calling fs_unlink() which relies on underlying file system's implementation. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: file: support creating a directoryAKASHI Takahiro2018-09-231-4/+10
| | | | | | | | | | | | | In efi world, there is no obvious "mkdir" interface, instead, Open() with EFI_FILE_MODE_CREATE in mode parameter and EFI_FILE_DIRECTORY in attributes parameter creates a directory. In this patch, efi_file_open() is extended so as to accept such a combination of parameters and call u-boot's mkdir interface for expected action. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: rename utf16_strlen, utf16_strnlenHeinrich Schuchardt2018-09-231-1/+1
| | | | | | | | | | | The function names utf16_strlen() and utf16_strnlen() are misnomers. The functions do not count utf-16 characters but non-zero words. So let's rename them to u16_strlen and u16_strnlen(). In utf16_dup() avoid assignment in if clause. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: Pass address to fs_read()Alexander Graf2018-09-231-1/+4
| | | | | | | | | | | | | The fs_read() function wants to get an address rather than the pointer to a buffer. So let's convert the passed buffer from pointer back a the address to make efi_loader on sandbox happier. Signed-off-by: Alexander Graf <agraf@suse.de> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* SPDX: Convert a few files that were missed beforeTom Rini2018-05-101-2/+1
| | | | | | | | | | | As part of the main conversion a few files were missed. These files had additional whitespace after the '*' and before the SPDX tag and my previous regex was too strict. This time I did a grep for all SPDX tags and then filtered out anything that matched the correct styles. Fixes: 83d290c56fab ("SPDX: Convert all of our single license tags to Linux Kernel style") Reported-by: Heinrich Schuchardt <xypron.debian@gmx.de> Signed-off-by: Tom Rini <trini@konsulko.com>
* efi_loader: implement EFI_FILE_SYSTEM_INFOHeinrich Schuchardt2018-04-051-0/+38
| | | | | | | | | | | Implement the information type EFI_FILE_SYSTEM_INFO in the service GetInfo() of the EFI_FILE_PROTOCOL. The volume label is not available in U-Boot. As a work-around use the partition name instead. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: use const for GUIDs in the EFI_FILE_PROTOCOLHeinrich Schuchardt2018-04-051-2/+2
| | | | | | | Use const efi_guid_t* when passing GUIDs. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: use correct types in EFI_FILE_PROTOCOLHeinrich Schuchardt2018-04-041-12/+35
| | | | | | | | In the EFI_FILE_PROTOCOL buffer sizes and positions are passed as UINTN and not as u64. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: add file/filesys supportRob Clark2017-09-201-0/+560
fallback.efi (and probably other things) use UEFI's simple-file-system protocol and file support to search for OS's to boot. Signed-off-by: Rob Clark <robdclark@gmail.com> [agraf: whitespace fixes, unsigned fixes] Signed-off-by: Alexander Graf <agraf@suse.de>