summaryrefslogtreecommitdiffstats
path: root/cmd/bootefi.c
Commit message (Collapse)AuthorAgeFilesLines
* efi_loader: create fdt reservation before copyHeinrich Schuchardt2018-12-021-9/+3
| | | | | | | | | | | When copying the device we must ensure that the copy does not fall into a memory area reserved by the same. So let's change the sequence: first create memory reservations and then copy the device tree. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: fix memory mapping for sandboxHeinrich Schuchardt2018-12-021-12/+17
| | | | | | | | | | | | | | The sandbox is using a virtual address space which is neither the physical address space of the operating system nor the virtual address space in which Linux aplications live. The addresses used insided the flattened device tree use this sandbox virtual address space. The EFI subsystem uses the virtual address space of the operating system and this is where the fdt is stored. Fix all incorrect addresses for the fdt in cmd/bootefi.cmd. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: macro efi_size_in_pages()Heinrich Schuchardt2018-12-021-9/+6
| | | | | | | | | | | When allocating EFI memory pages the size in bytes has to be converted to pages. Provide a macro efi_size_in_pages() for this conversion. Use it in the EFI subsystem and correct related comments. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi: Rename bootefi_test_finish() to bootefi_run_finish()Simon Glass2018-12-021-22/+24
| | | | | | | | | | This function can be used from do_bootefi_exec() so that we use mostly the same code for a normal EFI application and an EFI test. Rename the function and use it in both places. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi: Create a function to set up for running EFI codeSimon Glass2018-12-021-21/+31
| | | | | | | | | | | | | | There is still duplicated code in efi_loader for tests and normal operation. Add a new bootefi_run_prepare() function which holds common code used to set up U-Boot to run EFI code. Make use of this from the existing bootefi_test_prepare() function, as well as do_bootefi_exec(). Also shorten a few variable names. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi: Split out test init/uninit into functionsSimon Glass2018-12-021-21/+64
| | | | | | | | | | | | The functions in bootefi are very long because they mix high-level code and control with the low-level implementation. To help with this, create functions which handle preparing for running the test and cleaning up afterwards. Also shorten the awfully long variable names here. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi: Check for failure to create objects in selftestSimon Glass2018-12-021-0/+5
| | | | | | | | | At present a few error conditions are not checked. Before refactoring this code, add some basic checks. Note that this code still leaks memory in the event of error. This will be tackled after the refactor. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: carving out memory reservationsHeinrich Schuchardt2018-12-021-1/+10
| | | | | | | | | | | | The "Devicetree Specification 0.2" does not prescribe that memory reservations must be EFI page aligned. So let's not make such an assumption in our code. Do not carve out the pages for the device tree. This memory area is already marked as EFI_RUNTIME_SERVICES_DATA. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: memory reservation for fdtHeinrich Schuchardt2018-12-021-16/+5
| | | | | | | | | | | | | | In copy_fdt() we allocate EFI pages for the fdt plus extra 12 KiB as EFI_RUNTIME_SERVICES_DATA. Afterwards in efi_install_fdt() we overwrite part of this memory allocation by marking it as EFI_BOOT_SERVICES_DATA. Remove the code marking the fdt as EFI_BOOT_SERVICES_DATA. Cf. commit 17ff6f02f5ad ("efi_loader: store DT in EFI_RUNTIME_SERVICES_DATA memory") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: fix typosHeinrich Schuchardt2018-12-021-1/+1
| | | | | | | Fix typos in EFI subsystem comments. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: add efi_dp_from_name()AKASHI Takahiro2018-12-021-34/+8
| | | | | | | | Factor out efi_set_bootdev() and extract efi_dp_from_name(). This function will be used to set a boot device in efishell command. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: rename parent to headerHeinrich Schuchardt2018-12-021-6/+6
| | | | | | | | Rename the component parent of some EFI objects to header. This avoids misunderstandings. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: typedef struct efi_object *efi_handle_tHeinrich Schuchardt2018-12-021-14/+14
| | | | | | | | | | | | All our handles point to a struct efi_object. So let's define the efi_handle_t accordingly. This helps us to discover coding errors much more easily. This becomes evident by the corrections to the usage of handles in this patch. Rename variable image_handle to image_obj where applicable. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: execute efi_save_gd() firstHeinrich Schuchardt2018-10-161-17/+7
| | | | | | | | | | | | | | | If DEBUG is defined we may be calling EFI_CALL already during the initialization of the EFI subsystem. We must make sure efi_save_gd() has already been called at that moment. Anyway it is better to have this call in one location instead of three. This fixes an illegal memory access occurring since 4e6b5d6503ce ("efi_loader: create root node") with DEBUG = 1. Fixes: 4e6b5d6503ce ("efi_loader: create root node") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: refactor efi_setup_loaded_image()Heinrich Schuchardt2018-09-231-27/+40
| | | | | | | | | | | | | | | Create the handle of loaded images and the EFI_LOADED_IMAGE_PROTOCOL inside efi_setup_loaded_image(). Do not use local variables. Currently we expect the loaded image handle to point to the loaded image protocol. Additionally we have appended private fields to the protocol. With the patch the handle points to a loaded image object and the private fields are added here. This matches how we handle the net and the gop object. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: Fix loaded_image handle passing from EL3Alexander Graf2018-09-231-1/+1
| | | | | | | | | | | | | | | When running in EL3 mode on AArch64, we have to first drop to EL2 to execute a UEFI payload. When dropping down, the arguments to the entry point have to stay identical to the ones for normal entry though. In commit ea54ad59286 ("efi_loader: pass handle of loaded image") we incorrectly changed that logic and had the el3 entry path diverge. Fix it up by syncing it back to what it's supposed to be. Fixes: ea54ad59286 ("efi_loader: pass handle of loaded image") Signed-off-by: Alexander Graf <agraf@suse.de> Reviewed-by: Mark Kettenis <kettenis@openbsd.org>
* efi_loader: create root nodeHeinrich Schuchardt2018-09-231-0/+5
| | | | | | | | | | Currently we assign a lot of protocols to loaded images though these protocols are not related to them. Instead they should be installed on a separate handle. Via the device path it is the parent to the devices like the network adapter. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: memory leak in efi_set_bootdev()Heinrich Schuchardt2018-09-231-0/+7
| | | | | | | | efi_set_bootdev() may be called repeatedly. Free the memory allocated for device paths in previous calls. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: do not use local variable for handleHeinrich Schuchardt2018-09-231-7/+12
| | | | | | | | Do not use a local variable for the handle backing the memory device path. Adjust relate comments. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: buffer size for load optionsHeinrich Schuchardt2018-09-231-2/+4
| | | | | | | | | | The number of bytes in an utf-8 string is an upper limit for the number of words in the equivalent utf-16 string. In so far the inumbant coding works correctly. For non-ASCII characters the utf-16 string is shorter. With the patch only the necessary buffer size is allocated for the load options. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi: sandbox: Tidy up copy_fdt() to work with sandboxSimon Glass2018-09-231-29/+50
| | | | | | | | | | | | | | | | | | | | | | | | At present this function takes a pointer as its argument, then passes this to efi_allocate_pages(), which actually takes an address. It uses casts, which are not supported on sandbox. Also the function calculates the FDT size rounded up to the neared EFI page size, then its caller recalculates the size and adds a bit more to it. This function is much better written as something that works with addresses only, and returns both the address and the size of the relocated FDT. Also, copy_fdt() returns NULL on error, but really should propagate the error from efi_allocate_pages(). To do this it needs to return an efi_status_t, not a void *. Update the code in this way, so that it is easier to follow, and also supports sandbox. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi: Relocate FDT to 127MB instead of 128MBSimon Glass2018-09-231-2/+2
| | | | | | | | Sandbox only has 128MB of memory so we cannot relocate the device tree up to start at 128MB. Use 127MB instead, which should be safe. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: remove unused efi_get_time_init()Heinrich Schuchardt2018-07-251-3/+0
| | | | | | | | | | | | | Remove unused function efi_get_time_init(). Initialization of the RTC has to be done in board bring up not in the EFI subsystem. There is no RTC device in the UEFI spec. The RTC is only accessed through the runtime services. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: calculate crc32 for EFI tablesHeinrich Schuchardt2018-07-251-0/+5
| | | | | | | | | For the boot and runtime services tables and for the system table the crc32 has to be set in the header. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi: Drop error return in efi_carve_out_dt_rsv()Simon Glass2018-07-251-10/+14
| | | | | | | | | | | | | This function currently returns an error code, but never uses it. There is no function comment so it is not obvious why. Presuambly the error is not important. Update the function to explain its purpose and why it ignores the error. Drop the useful error return value. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Alexander Graf <agraf@suse.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi: Tidy up device-tree-size calculation in copy_fdt()Simon Glass2018-07-251-2/+6
| | | | | | | | | | This is a bit confusing at present since it adds 4KB to the pointer, then rounds it up. It looks like a bug, but is not. Move the 4KB addition into a separate statement and expand the comment. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: Use map_sysmem() in bootefi commandAlexander Graf2018-07-251-5/+8
| | | | | | | | | | The bootefi command gets a few addresses as values passed in. In sandbox, these values are in U-Boot address space, so we need to make sure we explicitly call map_sysmem() on them to be able to access them. Signed-off-by: Alexander Graf <agraf@suse.de> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: ARM: don't attempt to enter non-secure mode twiceMark Kettenis2018-07-251-1/+5
| | | | | | | | | Multiple EFI binaries may be executed in sequence. So if we already are in non-secure mode after running the first one we should skip the switching code since it no longer works once we're non-secure. Signed-off-by: Mark Kettenis <kettenis@openbsd.org> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: ARM: run EFI payloads non-secureMark Kettenis2018-07-251-0/+33
| | | | | | | | | | | | | If desired (and possible) switch into HYP mode or non-secure SVC mode before calling the entry point of an EFI application. This allows U-Boot to provide a usable PSCI implementation and makes it possible to boot kernels into hypervisor mode using an EFI bootloader. Based on diffs from Heinrich Schuchardt and Alexander Graf. Signed-off-by: Mark Kettenis <kettenis@openbsd.org> [agraf: Fix indentation] Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: Install ACPI configuration tablesBin Meng2018-07-021-0/+5
| | | | | | | | ACPI tables can be passed via EFI configuration table to an EFI application. This is only supported on x86 so far. Signed-off-by: Bin Meng <bmeng.cn@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
* efi_loader: Allocate memory handle for mem dpAlexander Graf2018-06-141-0/+9
| | | | | | | | | | | | | | | When we boot using memdp (bootefi on an address without previous load that populates the device path) then the memory device path we pass in is not backed by any handle. That can result in weird effects. For example grub gets very grumpy about this inside the efi_net module and just loops endlessly. So let's expose a simple handle that the memory device path is backed on. That way any code that looks for the device the dp is on, finds one. Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: avoid anonymous constants for AllocatePagesHeinrich Schuchardt2018-06-031-2/+4
| | | | | | | Do not use anonymous constants when calling efi_allocage_pages. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: allow unaligned memory accessHeinrich Schuchardt2018-06-031-0/+13
| | | | | | | | | | | The UEFI spec mandates that unaligned memory access should be enabled if supported by the CPU architecture. This patch adds an empty weak function unaligned_access() that can be overridden by an architecture specific routine. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_selftest: do not call efi_init_obj_list() twiceHeinrich Schuchardt2018-06-031-2/+0
| | | | | | | | Remove a superfluous call to efi_init_obj_list() invoked by 'bootefi selftest'. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> 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>
* Revert "Kconfig: cmd: Make networking command dependent on NET"Joe Hershberger2018-04-131-2/+2
| | | | | | | | | This reverts the parts of commit 3b3ea2c56ec4bc5588281fd103c744e608f8b25c where it changed the EFI dependency on NET. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com> Reviewed-by: Duncan Hare <dh@synoia.com>
* efi_loader: Respect DT reserved regionsAlexander Graf2018-04-061-0/+26
| | | | | | | | | | | | | With legacy boot (booti, bootz), people can declare memory regions as reserved using device tree memory reservations. This feature is some times used to indicate memory regions that should not be touched. Since in a UEFI world, the DT memory reservations do not get honored, let's copy them into the UEFI memory map so everyone has a coherent view of the world and we give people the chance to add reservations on demand. Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: correctly determine the boot partitionHeinrich Schuchardt2018-04-041-13/+4
| | | | | | | | | | | | | | | The device path of the loaded image should be set to the partition from which the image was loaded. This requires using the same logic as the load command. Without the patch the device path pointed to the whole disk after executing load mmc 0: 0x43000000 FILE and not to the boot partition from which the file was actually loaded. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: support device tree for bootefi selftestHeinrich Schuchardt2018-04-041-47/+64
| | | | | | | | | | | The second argument of the bootefi command should always be usable to specify a device tree. This was missing for bootefi selftest and bootefi hello. Proper error handling is added. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: check initialization of EFI subsystem is successfulHeinrich Schuchardt2018-04-041-20/+47
| | | | | | | | | | | | | | Up to now errors in the initialization of the EFI subsystems was not checked. If any initialization fails, leave the bootefi command. We do not retry initialization because this would require to undo all prior initalization steps. Suggested-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: do_bootefi_exec should always return an EFI status codeHeinrich Schuchardt2018-04-041-2/+2
| | | | | | | | The return type of do_bootefi_exec() is efi_status_t. So in case of an error we should always return an EFI status code. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: simplify calling efi_init_obj_listHeinrich Schuchardt2018-04-041-8/+8
| | | | | | | | | | | | efi_init_obj_list() should be executed only once. Rather than having the caller check this variable and the callee set it, move all access to the variable inside the function. This reduces the logic needed to call efi_init_obj_list(). Suggested-by: Simon Glass <sjg@chromium.org> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* libfdt: move headers to <linux/libfdt.h> and <linux/libfdt_env.h>Masahiro Yamada2018-03-051-2/+2
| | | | | | | | | | | | | | | | | Thomas reported U-Boot failed to build host tools if libfdt-devel package is installed because tools include libfdt headers from /usr/include/ instead of using internal ones. This commit moves the header code: include/libfdt.h -> include/linux/libfdt.h include/libfdt_env.h -> include/linux/libfdt_env.h and replaces include directives: #include <libfdt.h> -> #include <linux/libfdt.h> #include <libfdt_env.h> -> #include <linux/libfdt_env.h> Reported-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
* Kconfig: cmd: Make networking command dependent on NETMichal Simek2018-02-271-2/+2
| | | | | | | | Enable networking command only when NET is enabled. And remove selecting NET for CMD_NET Signed-off-by: Michal Simek <michal.simek@xilinx.com> Signed-off-by: Tom Rini <trini@konsulko.com>
* efi_loader: fix the online help for bootefi bootmgrHeinrich Schuchardt2018-02-101-1/+1
| | | | | | | | The bootefi command is missing in the online help for bootefi bootmgr. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: catch misspelled bootefi subcommandHeinrich Schuchardt2018-01-281-0/+3
| | | | | | | | | | | | | | If 'bootefi hello' or 'bootefi selftest' can be executed depends on the configuration. If an invalid non-numeric 1st argument is passed to bootefi, e.g. 'bootefi hola', this string is converted to 0 and U-Boot jumps to this typically invalid address. With the patch the online help is shown instead. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: Always use EFIAPI instead of asmlinkageAlexander Graf2018-01-281-5/+6
| | | | | | | | | | | | | | | | | | | | | | | EFI calls are usually defined as asmlinkage. That means we pass all parameters to functions via the stack x86_32. On x86_64 however, we need to also stick to the MS ABI calling conventions, which the EFIAPI define conveniently handles for us. Most EFI functions were also marked with EFIAPI, except for the entry call. So this patch adjusts all entry calls to use EFIAPI instead of the manual asmlinkage attribute. While at it, we also change the prototype of the entry point to return efi_status_t instead of ulong, as this is the correct prototype definition. Signed-off-by: Alexander Graf <agraf@suse.de> --- v1 -> v2: - Use efi_status_t in all occurences
* efi_driver: EFI block driverHeinrich Schuchardt2018-01-221-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch provides * a uclass for EFI drivers * a EFI driver for block devices For each EFI driver the uclass * creates a handle * adds the driver binding protocol The uclass provides the bind, start, and stop entry points for the driver binding protocol. In bind() and stop() it checks if the controller implements the protocol supported by the EFI driver. In the start() function it calls the bind() function of the EFI driver. In the stop() function it destroys the child controllers. The EFI block driver binds to controllers implementing the block io protocol. When the bind function of the EFI block driver is called it creates a new U-Boot block device. It installs child handles for all partitions and installs the simple file protocol on these. The read and write functions of the EFI block driver delegate calls to the controller that it is bound to. A usage example is as following: U-Boot loads the iPXE snp.efi executable. iPXE connects an iSCSI drive and exposes a handle with the block IO protocol. It calls ConnectController. Now the EFI block driver installs the partitions with the simple file protocol. iPXE uses the simple file protocol to load Grub or the Linux Kernel. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> [agraf: add comment on calloc len] Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: store DT in EFI_RUNTIME_SERVICES_DATA memoryHeinrich Schuchardt2018-01-221-2/+2
| | | | | | | | | | | The device tree is needed at runtime. So we have to store it in EFI_RUNTIME_SERVICES_DATA memory. The UEFI spec recommends to store all configuration tables in EFI_RUNTIME_SERVICES_DATA memory. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
* efi_loader: consistently use efi_handle_t for handlesHeinrich Schuchardt2018-01-221-5/+5
| | | | | | | | | We should consistently use the efi_handle_t typedef when referring to handles. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>